Touchless hand sanitiser dispenser
Hold your hand under it and a metal-gear servo presses the pump for you.
Shop by category
Shop all componentsA stalled DC motor draws several times its running current and overheats in seconds. The ACS712 watches the current through the motor's + wire. If it stays above 1.5 A for a tenth of a second, the relay cuts the motor and the red light stays on until you clear the jam and press the button.
Keep to low-voltage loads unless a qualified electrician wires the mains side in an earthed, closed enclosure.
Tick anything you already have and the total updates.
Connects the Uno to your computer to upload code and power it
Measures the current flowing through its two screw terminals with a Hall sensor, so the measured circuit stays electrically separate from the board.
An electrically isolated switch that lets a 3.3/5 V pin turn a 12 V (or mains) load on and off.
Follow the colours: red is power, dark grey is ground, blue is a signal.
motor_stall_current_cutoff.inoVerify & upload in Electrolark// Motor stall current cut-off
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "motor-stall-current-cutoff"
// ---- pins ----
const uint8_t CURRENT_PIN = A0;
const uint8_t RELAY_PIN = 2;
const uint8_t LED_RED = 3;
const uint8_t BUTTON_PIN = 4;
const int ADC_MAX = 1023; // 10-bit analog input
const float VREF = 5.0f;
const float ACS_MV_PER_A = 185.0; // 5 A module: 185 mV per amp (20 A: 100, 30 A: 66)
float acsZero = 0; // output with no current, measured at start-up
const bool RELAY_ACTIVE_LOW = true; // most relay modules switch on when IN is LOW
// ---- latest readings ----
float currentA = 0;
const float TRIP_LEVEL = 1.5; // A: cut the load above this
const unsigned long TRIP_MS = 100; // must stay above the limit this long (ignores start-up surges)
bool tripped = false;
unsigned long overSince = 0;
float readCurrentA() {
long s = 0;
for (int i = 0; i < 100; i++) s += analogRead(CURRENT_PIN); // average out the noise
float mv = (s / 100.0f - acsZero) * VREF * 1000.0f / ADC_MAX;
float a = mv / ACS_MV_PER_A;
return fabs(a) < 0.05f ? 0 : a;
}
void setRelay(bool on) { digitalWrite(RELAY_PIN, (on != RELAY_ACTIVE_LOW) ? HIGH : LOW); }
void setRedLed(bool on) { digitalWrite(LED_RED, on ? HIGH : LOW); }
void setup() {
Serial.begin(115200);
{ long s = 0; for (int i = 0; i < 200; i++) { s += analogRead(CURRENT_PIN); delay(1); } acsZero = s / 200.0f; } // switch the load off while the board starts
pinMode(RELAY_PIN, OUTPUT);
setRelay(false);
pinMode(LED_RED, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
setRelay(true);
setRedLed(false);
}
void loop() {
currentA = readCurrentA();
if (!tripped) {
if (fabs(currentA) > TRIP_LEVEL) { if (!overSince) overSince = millis(); } else overSince = 0;
if (overSince && millis() - overSince > TRIP_MS) {
tripped = true; setRelay(false);
Serial.print(F("TRIPPED at ")); Serial.println(currentA, 2);
}
}
if (tripped && digitalRead(BUTTON_PIN) == LOW) { tripped = false; overSince = 0; setRelay(true); Serial.println(F("Reset")); delay(300); }
setRedLed(tripped);
static unsigned long lastLog = 0;
if (millis() - lastLog > 500) { lastLog = millis(); Serial.print(currentA, 2); Serial.println(F(" A")); }
delay(5);
}
The sketch above runs here on a simulated Arduino Uno. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
The zero point was taken with the load on. Switch the load off and reset the board.
Current flows the other way. Swap the wires on IP+ and IP−, or ignore the sign.
Load must be on COM and NO, with its own supply in series.
Your module may be active-HIGH. Set RELAY_ACTIVE_LOW to false.
Some 5 V relay boards do not fully switch off with 3.3 V logic. Remove the JD-VCC jumper, feed JD-VCC from 5 V and VCC from 3.3 V, or use a relay board made for 3.3 V input.
LED is reversed; flip it. Check the 220 Ω resistor is in series.
The button is rotated 90°; legs on the same side are already connected. Turn it.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider. Analog readings run 0–4095 instead of 0–1023, which the ADC_MAX constant handles.
The relay is rated for mains, but mains wiring is dangerous. Keep this build on low-voltage loads (12 V pumps, fans, LED strips), or have a qualified electrician fit the relay inside an earthed, closed enclosure.
Use a 5 V USB phone charger or a power bank into the board's USB port. Loads such as pumps, fans and solenoids need their own supply.
11 parts: Uno R3 CH340G ATmega328p Compatible Development Board, Arduino USB-A to USB-B Data Cable for UNO/MEGA, ACS712 Hall-Effect Current Sensor Module (5A), 5V Relay Module with Optocoupler (1 channel), Through-Hole LED Pack (Pack of 10), Tactile Push Button Switch, Resistor Assortment Kit (30 Values), BO DC Gear Motor 3–12V, DC Power Adapter 12V 2A (5.5x2.1mm), Solderless Breadboard (830 points), plus 1 more. Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1–2 hours. The build on this page has 10 steps.
No. This page has the complete, tested code (motor_stall_current_cutoff.ino).
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹798 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Current-limiting resistors for LEDs; Hall-effect current sensing; Isolation, relays and switching higher-power loads; Pull-ups and debouncing.
Ideas that reuse this build: Electronic fuse and DC current meter. They are listed under Take it further on this page.
Hold your hand under it and a metal-gear servo presses the pump for you.
Wave your hand and the lid lifts by itself, then closes after three seconds.
Your first motion project: turn the knob and the servo follows.
Dial in an exact servo angle, 2° per click, shown on screen.
Learning project. Check every circuit and the datasheet of each part before you power it up.
0.00 A 0.00 A 0.00 A 0.00 A 0.00 A
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.