Touchless hand sanitiser dispenser
Hold your hand under it and a metal-gear servo presses the pump for you.
Shop by category
Shop all componentsStarting a motor at full power gives a big current spike and a jolt on the shaft. This sketch moves the speed towards the knob setting four steps every 20 ms, so the motor starts and stops smoothly. The button flips the direction, and the ramp takes care of the change too.
Tick anything you already have and the total updates.
Connects the Uno to your computer to upload code and power it
Dual H-bridge that lets the board drive two DC motors forwards, backwards and at variable speed.
A 10 kΩ knob that works as a voltage divider, giving an analog value you can map to anything.
Raises the cell's 3.0–4.2 V to a steady 5 V for the board
Follow the colours: red is power, dark grey is ground, blue is a signal.
Battery + goes to the L298N 12V terminal and battery − to GND; join that GND to the Uno GND. Power the Uno from its own USB power bank. Set the boost converter to 5.0 V with a multimeter before connecting the board. Cell + → boost IN+, cell − (TP4056 OUT−) → boost IN−, then boost OUT+ → board 5V pin and OUT− → GND. A bare 18650 (3.0–4.2 V) cannot run a 5 V board by itself.
soft_start_motor_controller.inoVerify & upload in Electrolark// Soft-start motor controller with a speed knob
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "soft-start-motor-controller"
// ---- pins ----
const uint8_t ENA = 3;
const uint8_t IN1 = 2;
const uint8_t IN2 = 4;
const uint8_t IN3 = 6;
const uint8_t IN4 = 7;
const uint8_t ENB = 5;
const uint8_t POT_PIN = A0;
const uint8_t BUTTON_PIN = 8;
const int ADC_MAX = 1023; // 10-bit analog input
const float VREF = 5.0f;
// ---- latest readings ----
int potPct = 0;
int current = 0; // speed now: -255 to 255
int direction = 1;
unsigned long lastStep = 0;
// speed: -255 (full reverse) to 255 (full forward)
void drive(int left, int right) {
digitalWrite(IN1, left >= 0 ? HIGH : LOW);
digitalWrite(IN2, left >= 0 ? LOW : HIGH);
analogWrite(ENA, constrain(abs(left), 0, 255));
digitalWrite(IN3, right >= 0 ? HIGH : LOW);
digitalWrite(IN4, right >= 0 ? LOW : HIGH);
analogWrite(ENB, constrain(abs(right), 0, 255));
}
void setup() {
Serial.begin(115200);
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
drive(0, 0);
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { direction = -direction; while (digitalRead(BUTTON_PIN) == LOW) delay(10); }
potPct = (int)(analogRead(POT_PIN) * 100L / ADC_MAX);
int target = map(potPct, 0, 100, 0, 255) * direction;
if (millis() - lastStep >= 20) { // move 4 steps towards the target every 20 ms: a gentle ramp
lastStep = millis();
if (current < target) current = min(current + 4, target);
else if (current > target) current = max(current - 4, target);
drive(current, 0);
}
}
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 ENA/ENB jumpers must be removed and wired to PWM pins, and the battery GND must connect to the board GND.
Swap that motor's two wires on the screw terminal.
The wiper is on an outer pin. Move the signal wire to the middle leg.
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.
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, L298N Dual H-Bridge Motor Driver Module, 16mm Rotary Potentiometer 10kΩ (Linear), Tactile Push Button Switch, TT Gear Motor (Yellow) 3–6V, 2 × 18650 Battery Holder, 2 × 18650 Li-ion Rechargeable Cell 2600mAh, MT3608 Mini Boost Converter Module, 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 beginner project and takes about 1–2 hours. The build on this page has 9 steps.
No. This page has the complete, tested code (soft_start_motor_controller.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 ₹948 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.
H-bridges and PWM speed control; Pull-ups and debouncing; Voltage dividers and analogRead().
Ideas that reuse this build: Knob speed motor controller and PWM fan speed knob. 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.
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.