DIY Smart Dustbin with Arduino
Wave your hand and the lid opens by itself! A red light tells you when the bin is full. Let's build a real robot that keeps our planet clean. 🌍
What Will We Make?
An automatic dustbin using sensors and a servo motor – a great beginner robotics project.
Sensor 1: Hand detector
Sits at the front. Opens the lid when your hand is within 20 cm.
Sensor 2: Fullness checker
Faces down inside the lid. Measures how high the trash is.
LEDs and buzzer
Green means ready. Red plus beep means please empty me!
Parts You Need
Ask a grown-up to help you shop. Everything is easy to find online.
Arduino Uno ×1
The brain of our robot.
HC-SR04 ultrasonic ×2
The robot's "eyes".
SG90 servo motor ×1
Moves the lid up and down.
Green + red LED
Status lights, one of each.
Active buzzer ×1
Beeps when the bin is full.
220Ω resistors ×2
Protect the LEDs.
Breadboard + jumper wires
No soldering needed!
Small box or bin + tape
Use a clean plastic tub or cardboard box with a lid.
Circuit Diagram
Follow the colours. Red wires are power, black wires are ground.
| Part | Pin on part | Arduino pin |
|---|---|---|
| Sensor 1 (hand) | TRIG / ECHO | D9 / D10 |
| Sensor 2 (fullness) | TRIG / ECHO | D7 / D8 |
| Both sensors | VCC / GND | 5V / GND |
| Servo SG90 | Signal (orange) | D6 |
| Servo SG90 | Red / Brown | 5V / GND |
| Green LED | Long leg through 220Ω | D4 (short leg to GND) |
| Red LED | Long leg through 220Ω | D5 (short leg to GND) |
| Buzzer | + / − | D3 / GND |
Step-by-Step Instructions
Prepare your dustbin
Take a small box or tub with a lid. Fix the servo motor beside the back edge of the lid using strong tape or hot glue (ask an adult). Tape a craft stick from the servo arm to the lid, so when the arm turns the lid lifts.
Place the sensors
Stick Sensor 1 on the front of the bin at hand height, looking outward. Tape Sensor 2 under the lid, looking down at the trash inside.
Wire power first
Connect Arduino 5V to the breadboard red rail and GND to the blue rail. Every part shares these two rails.
Connect the parts
Use the wiring table above. Put each LED's long leg toward the resistor. Double-check TRIG and ECHO are not swapped.
Upload the code
Install the free Arduino IDE, plug in the USB cable, choose Tools → Board → Arduino Uno, paste the code below and press Upload ➜.
Test and tune
Wave your hand 10 cm from Sensor 1. The lid should open, wait 3 seconds, then close. Now hold a paper 5 cm below Sensor 2 – the red LED and buzzer switch on!
The Arduino Code
Every line has a comment, so you can learn as you go.
#include <Servo.h> // library to control the servo Servo lid; // our lid motor // ---- Pin numbers ---- const int trigHand = 9, echoHand = 10; // front sensor const int trigBin = 7, echoBin = 8; // inside sensor const int servoPin = 6, greenLed = 4, redLed = 5, buzzer = 3; const int HAND_CM = 20; // open lid if hand is closer than this const int FULL_CM = 8; // bin is full if trash is closer than this // Measure distance in centimetres long readCm(int trig, int echo) { digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); // send sound pulse digitalWrite(trig, LOW); long time = pulseIn(echo, HIGH, 30000); // wait for echo if (time == 0) return 999; // nothing found return time * 0.034 / 2; // sound speed maths } void setup() { pinMode(trigHand, OUTPUT); pinMode(echoHand, INPUT); pinMode(trigBin, OUTPUT); pinMode(echoBin, INPUT); pinMode(greenLed, OUTPUT); pinMode(redLed, OUTPUT); pinMode(buzzer, OUTPUT); lid.attach(servoPin); lid.write(0); // lid starts closed } void loop() { long hand = readCm(trigHand, echoHand); if (hand < HAND_CM) { // someone is near! lid.write(90); // open lid delay(3000); // keep open 3 seconds lid.write(0); // close lid delay(800); // let it settle } long trash = readCm(trigBin, echoBin); // check fullness (lid closed) if (trash < FULL_CM) { // bin is FULL digitalWrite(redLed, HIGH); digitalWrite(greenLed, LOW); tone(buzzer, 1000, 200); // short beep } else { // bin has space digitalWrite(redLed, LOW); digitalWrite(greenLed, HIGH); } delay(200); }
HAND_CM to make the sensor more or less sensitive, change delay(3000) for longer open time, or change write(90) to write(120) for a wider lid.Fix-It Corner 🔧
Lid never opens
Check the servo signal wire is on D6 and the sensor's TRIG and ECHO are not swapped.
Lid jitters
Power dip. Use a fresh USB cable or a 4×AA battery pack for the servo, sharing GND with the Arduino.
Red LED always on
Sensor 2 sees the lid or a wall. Aim it straight down and increase the mounting height, or lower FULL_CM.
LED not glowing
Flip it around. The long leg goes toward the Arduino pin.
Upgrade Ideas 🚀
Bluetooth alerts
Add an HC-05 module to send "Bin Full" to your phone.
LCD display
Show the fill level as a percentage.
Solar power
Charge a battery pack with a small solar panel.
Two-bin sorter
Build separate wet and dry waste bins.
Frequently Asked Questions
Which sensor does a smart dustbin use?
An HC-SR04 ultrasonic sensor. It measures distance with sound waves, just like a bat does.
Can I use only one sensor?
Yes! Remove the second sensor, red LED and buzzer for a simpler "open-lid only" version, then add them later.
Is this project safe for kids?
Yes. It runs on 5V from USB. Kids aged 9 to 14 should build it with an adult nearby, especially when using hot glue or scissors.
What will I learn?
How sensors, motors and code work together, plus how to read distances, control a servo and use if/else decisions.

Comments
Post a Comment