Build it step by step
0 of 7 doneWire the sensor and display
Both to 5V, GND, A4 and A5.
Wire the buzzer
Plus to D8, minus to GND.
Install the libraries
Adafruit VL53L0X, SSD1306 and GFX.
Upload the sketch
The display says Put hands under sensor.
Hold a hand about 10 cm under the sensor
The countdown starts from 20.
Keep it there
The bar fills and the buzzer beeps at zero.
Take the hand away early
The count starts again.
How do you build a hand-wash timer?
A time-of-flight sensor above a basin sees your hands, starts a twenty-second countdown on a small OLED and beeps when it is done, restarting if the hands leave early. You need Arduino Nano, VL53L0X time-of-flight distance sensor, SSD1306 OLED Display, Passive buzzer, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 7 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- DisplaysBuy
- Motors & ActuatorsBuyPassive buzzer × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| VL53L0X VIN | Nano 5V | Sensor supply (the module has a regulator) |
| VL53L0X GND | Nano GND | Common ground |
| VL53L0X SDA and SCL | Nano A4 and A5 | I2C, address 0x29 |
| OLED VCC | Nano 5V | Power (check your OLED accepts 5 V, otherwise use 3V3) |
| OLED GND | Nano GND | Common ground |
| OLED SDA and SCL | Nano A4 and A5 | Shared I2C bus, address 0x3C |
| Passive buzzer + | Nano D8 | Tone output |
| Passive buzzer - | Nano GND | Return |
Code
The VL53L0X measures distance by timing a pulse of invisible laser light as it bounces back, so it can tell when hands are under it. The program counts the time only while something is closer than 25 centimetres, and shows the seconds left and a bar on the OLED. If the hands leave for more than two seconds, the count starts again, so a quick rinse does not count as a wash. After twenty seconds the buzzer beeps three times and the display tells you to rinse and dry, and the timer waits until the hands go away before it is ready for the next wash. Twenty seconds is the length of wash usually recommended, and the timer only helps you count it. It is a reminder and not medical advice. The sensor and the board must be kept dry and away from the tap spray, for example in a small box on the wall beside the basin or on a shelf above it, with the sensor looking down through a clear opening. Powered over USB from a safe supply and never anywhere near mains water fittings.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_VL53L0X lox;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int BUZZER = 8;
const int NEAR_MM = 250; // hands closer than this count as washing
const unsigned long TARGET_MS = 20000; // twenty seconds of washing
const unsigned long GONE_MS = 2000; // hands away this long restarts the count
unsigned long washed = 0;
unsigned long lastSeen = 0;
unsigned long lastLoop = 0;
bool finished = false;
bool handsPresent() {
VL53L0X_RangingMeasurementData_t m;
lox.rangingTest(&m, false);
return m.RangeStatus != 4 && m.RangeMilliMeter < NEAR_MM;
}
void draw(const char* line, int seconds, int percent) {
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.print(line);
oled.setTextSize(4);
oled.setCursor(40, 16);
oled.print(seconds);
oled.drawRect(0, 54, 128, 10, SSD1306_WHITE);
oled.fillRect(2, 56, constrain(percent, 0, 100) * 124 / 100, 6, SSD1306_WHITE);
oled.display();
}
void setup() {
pinMode(BUZZER, OUTPUT);
Wire.begin();
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
if (!lox.begin()) { while (true) {} }
draw("Put hands under sensor", 20, 0);
lastLoop = millis();
}
void loop() {
unsigned long now = millis();
unsigned long dt = now - lastLoop;
lastLoop = now;
bool present = handsPresent();
if (present) lastSeen = now;
if (finished) {
if (now - lastSeen > 3000) { // hands gone: ready for the next wash
finished = false;
washed = 0;
draw("Put hands under sensor", 20, 0);
}
delay(50);
return;
}
if (present) {
washed += dt;
int left = (TARGET_MS - min(washed, TARGET_MS) + 999) / 1000;
draw("Keep washing", left, washed * 100 / TARGET_MS);
if (washed >= TARGET_MS) {
finished = true;
draw("Done, rinse and dry", 0, 100);
for (int i = 0; i < 3; i++) { tone(BUZZER, 2000, 150); delay(250); }
}
} else if (washed > 0 && now - lastSeen > GONE_MS) {
washed = 0; // hands left early: start again
draw("Put hands under sensor", 20, 0);
}
delay(50);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Nothing under the sensor | Shows 20 and waits |
| Hand under the sensor | Counts down each second |
| Take the hand away for 3 seconds | Resets to 20 |
| Keep it there for 20 seconds | Three beeps and a done message |
| Remove the hand | Ready for the next wash |
If it does not work
Stays at 20
Check the hand is within 25 cm and the sensor wires are on A4 and A5.
Display blank
Check the OLED address 0x3C and the power wires.
Stops at lox begin
Check the sensor power and I2C wires.
Counts when nothing is there
Shield the sensor from reflections off the basin.
No beep
Check the buzzer is passive and on D8.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the hand-wash timer?
Arduino Nano, VL53L0X time-of-flight distance sensor, SSD1306 OLED Display, Passive buzzer, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the hand-wash timer take to build?
About 120 minutes for a beginner maker, in 7 steps.
How do I know the hand-wash timer works?
Nothing under the sensor: Shows 20 and waits. Hand under the sensor: Counts down each second. Take the hand away for 3 seconds: Resets to 20.
Stays at 20: what should I check?
Check the hand is within 25 cm and the sensor wires are on A4 and A5.
Display blank: what should I check?
Check the OLED address 0x3C and the power wires.
Stops at lox begin: what should I check?
Check the sensor power and I2C wires.
Counts when nothing is there: what should I check?
Shield the sensor from reflections off the basin.
