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 wheel with seven positions sits over a hole: one empty starting slot and six filled ones. At each dose time from the clock, the servo turns one slot so that dose drops into the cup below, and the buzzer beeps until the button is pressed (or for 15 minutes). Six slots cover two days of three doses.
A reminder aid only. A family member or carer should check the wheel is filled correctly and the doses are taken.
Tick anything you already have and the total updates.
The brain of the project
Works with the same pins and code as the original Arduino Nano.
Temperature-compensated real-time clock (±2 minutes a year) with a coin-cell backup, so the time survives power cuts.
Small hobby servo that turns to any angle from 0 to 180° on command.
Active buzzer with a built-in oscillator: apply power and it beeps at about 2.3 kHz.
Follow the colours: red is power, dark grey is ground, blue is a signal.
servo_pill_dispenser.inoVerify & upload in Electrolark// Timed pill dispenser wheel
// Geekobot project library · board: Arduino Nano
// Wiring diagram, parts list and build steps: Geekobot project page "servo-pill-dispenser"
#include <Wire.h>
#include <RTClib.h>
#include <Servo.h>
// ---- pins ----
const uint8_t SERVO_PIN = 3;
const uint8_t BUZZER_PIN = 2;
const uint8_t BUTTON_PIN = 4;
RTC_DS3231 rtc;
Servo servo;
const int DOSE_TIMES[][2] = {{8, 0}, {14, 0}, {21, 0}}; // dose times (24 h)
const int SLOTS = 7; // wheel positions 30 degrees apart: one empty start slot + six doses
const int SLOT_DEG = 30;
int slot = 0; // wheel starts at slot 0 (the empty slot over the hole)
int lastDoseMinute = -1;
bool waiting = false; // a dose is out and not yet taken
unsigned long doseAt = 0;
void setBuzzer(bool on) { digitalWrite(BUZZER_PIN, on ? HIGH : LOW); }
void nextSlot() {
if (slot >= SLOTS - 1) { Serial.println(F("Wheel empty: refill and reset")); return; }
slot++;
servo.write(slot * SLOT_DEG);
Serial.print(F("Dose ")); Serial.println(slot);
}
void setup() {
Serial.begin(115200);
if (!rtc.begin()) Serial.println(F("RTC not found"));
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set from the upload time
servo.attach(SERVO_PIN);
pinMode(BUZZER_PIN, OUTPUT);
setBuzzer(false);
pinMode(BUTTON_PIN, INPUT_PULLUP);
servo.write(0);
setBuzzer(false);
}
void loop() {
DateTime now = rtc.now();
int m = now.hour() * 60 + now.minute();
for (unsigned int i = 0; i < sizeof(DOSE_TIMES) / sizeof(DOSE_TIMES[0]); i++) {
if (m == DOSE_TIMES[i][0] * 60 + DOSE_TIMES[i][1] && lastDoseMinute != m) {
lastDoseMinute = m; nextSlot(); waiting = true; doseAt = millis();
}
}
if (waiting) {
setBuzzer((millis() / 400) % 4 == 0); // short beeps until the button is pressed
if (digitalRead(BUTTON_PIN) == LOW || millis() - doseAt > 900000UL) { waiting = false; setBuzzer(false); } // taken, or give up after 15 min
}
delay(100);
}
The sketch above runs here on a simulated Arduino Nano. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
The coin cell is flat or missing. Some modules need the charging resistor removed when using a CR2032.
Power the servo from a separate 5 V supply and join the grounds; add a 470 µF capacitor across the servo supply.
Low-triggered module: invert the logic in setBuzzer().
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.
Use a 5 V USB phone charger or a power bank into the board's USB port.
7 parts: Nano CH340 Development Board (Soldered), DS3231 Precision RTC Module with EEPROM, TowerPro SG90 9g Micro Servo (180°), Active Buzzer Module 3.3–5V, Tactile Push Button Switch, Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). 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 3 hours. The build on this page has 11 steps.
No. This page has the complete, tested code (servo_pill_dispenser.ino). Install these libraries first: RTClib and Servo.
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 ₹516 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.
Active vs passive buzzers; PWM pulses and servo control; Pull-ups and debouncing; Real-time clocks and backup batteries.
A reminder aid only. A family member or carer should check the wheel is filled correctly and the doses are taken.
Ideas that reuse this build: Medicine reminder with clock and Pillbox not-opened alarm. 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.