Arduino Automatic Touchless Smart Dustbin
Level 31 · The Bin Opens · 35 minutes
A dustbin that opens its own lid: the sensor says how far away you are, and the servo answers.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Make the bin lid open when somebody comes close. Wire it up: - HC-SR04: VCC 5V, GND GND, TRIG D4, ECHO D5 - Servo: signal D9, red 5V, brown GND Nearer than 20 cm: write 90, lid open. Nothing near: wait 1 second, then write 0. Time that wait from the last time you SAW somebody.
Components you’ll use
- Arduino Uno
- HC-SR04 Ultrasonic Distance Sensor
- SG90 Micro Servo
What you’ll build
A dustbin that opens its own lid when you walk up to it.
How it works
- Every pass of
loop()pulses TRIG and times the answer on ECHO. - Nearer than
20cm: write90, and the lid is open. - Nobody near for
1second: write0, and it shuts. - Serial prints
OPENandSHUTeach time the lid moves. - Drag the sensor slider in and out to play the part of the person.
The key idea
The wait is not timed from when the lid opened. It is timed from the last moment the sensor saw somebody.
Save that moment every pass: lastSeen = millis().
Then shut the lid only when millis() - lastSeen reaches 1000.
⚠ Watch out
A lid timed from the opening shuts on somebody who is still standing there. Hold the slider close and watch. If the lid drops while you are still there, you timed the wrong thing.
The interactive editor includes the wiring guide, code editor and simulation controls.