Summary
A smart dustbin working model opens its lid by itself when a hand comes within 20 cm. You can build one in about two hours, with no soldering, using an Arduino Uno, an HC-SR04 ultrasonic sensor, and an SG90 servo. Parts cost about ₹700 to ₹800. Below are the parts, circuit, copy-paste code, and exhibition tips.
A smart dustbin working model opens its lid automatically when a hand comes near. It uses an ultrasonic sensor to measure distance, an Arduino to decide, and a small servo motor to lift the lid. The full build costs under ₹800, takes about two hours, and needs no soldering. Parts, circuit, and code are below.
|
At a glance |
|
|
Parts cost |
About ₹700 to ₹800 |
|
Build time |
About 2 hours |
|
Skill level |
Beginner, no soldering |
|
Good for |
School science exhibitions, Class 6 to 10 |
How a smart dustbin works
Every smart dustbin working model does three jobs: it senses, decides, and acts. The HC-SR04 ultrasonic sensor sends out a short burst of sound at 40 kHz, too high for us to hear, and listens for the echo. The Arduino times that echo and turns it into a distance. For the full picture of how the sensor does this, read our guide on what an ultrasonic sensor is.

Sound travels about 343 metres per second, which is 0.0343 cm per microsecond. The pulse goes to the hand and back, so we halve the trip: distance (cm) = echo time (µs) × 0.0343 ÷ 2, which is the same as echo time ÷ 58. When that number drops to 20 cm or less for two readings in a row, the Arduino tells the SG90 servo to lift the lid.
Components and Supplies
Parts list
Everything except the bin and the power bank comes from our store, and the parts come to about ₹700 to ₹800.
|
Part |
What it does |
|
Reads the sensor and runs the code |
|
|
Measures how far the hand is |
|
|
Keeps the sensor upright and facing forward |
|
|
Lifts and lowers the lid |
|
|
Backup power only (main power is a USB power bank) |
|
|
Connects the backup battery to VIN |
|
|
Makes every connection |
|
|
Shares 5V and GND between parts |
From home: a small bin about 20 to 25 cm tall with a light lid (a shoebox works), an ice-cream stick, a glue gun or double-sided tape, the USB cable for uploading code, and a USB power bank to run the model.
|
BUILD IT: SMART DUSTBIN KIT
Every part from the list above, picked to work together out of the box: |
Circuit diagram
The sensor and servo both need 5V, but the Uno has only one 5V pin, so we run 5V and GND to the breadboard rails and share them from there.

|
From |
To |
|
HC-SR04 VCC |
Breadboard +5V rail |
|
HC-SR04 GND |
Breadboard GND rail |
|
HC-SR04 Trig |
Uno D11 |
|
HC-SR04 Echo |
Uno D10 |
|
SG90 red wire |
Breadboard +5V rail |
|
SG90 brown wire |
Breadboard GND rail |
|
SG90 orange wire |
Uno D9 |
|
Uno 5V and GND |
+5V rail and GND rail |
|
USB power bank (9V on VIN only as backup) |
Uno USB socket |
Power it from a USB power bank plugged into the Uno's USB socket. A 9V battery on VIN cannot feed the servo for long and will brown out within an hour on exhibition day, so keep it only as a backup. A 4xAA pack also works if it powers the servo alone: move the servo's red wire to the breadboard's second + rail, connect the pack's + there and its – to the GND rail, and keep the Uno on the power bank. Every ground must meet on the GND rail; a missing common ground is the most common reason a servo twitches or refuses to move.
Arduino code
The sketch uses the Servo library that ships with the Arduino IDE, so there is nothing extra to install. Select Arduino Uno under Tools > Board, pick the right port and click Upload. Open the Serial Monitor at 9600 baud to watch the live distance.
// Smart Dustbin Working Model - Robocraze
// HC-SR04 + SG90 servo + Uno R3 compatible board
#include
const int TRIG_PIN = 11;
const int ECHO_PIN = 10;
const int SERVO_PIN = 9;
const int OPEN_DISTANCE_CM = 20; // hand closer than this opens the lid
const int LID_CLOSED_ANGLE = 0;
const int LID_OPEN_ANGLE = 100; // raise if your lid needs a wider swing
const unsigned long HOLD_OPEN_MS = 3000; // lid closes 3 s after the hand leaves
Servo lid;
int nearCount = 0;
long readDistanceCm(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // 10 µs pulse starts a measurement
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH, 30000UL); // wait up to 30 ms
if (duration == 0) return -1; // no echo, nothing in range
return duration / 58; // round-trip time in µs to cm
}
bool handIsNear() {
long d = readDistanceCm(TRIG_PIN, ECHO_PIN);
Serial.print("Distance: ");
Serial.print(d);
Serial.println(" cm");
return (d > 0 && d <= OPEN_DISTANCE_CM);
}
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
lid.attach(SERVO_PIN);
lid.write(LID_CLOSED_ANGLE);
delay(500);
}
void loop() {
if (handIsNear()) {
nearCount++;
} else {
nearCount = 0;
}
if (nearCount >= 2) { // two close readings in a row
lid.write(LID_OPEN_ANGLE);
unsigned long lastSeen = millis();
while (millis() - lastSeen < HOLD_OPEN_MS) {
if (handIsNear()) lastSeen = millis(); // hand still there: keep open
delay(60);
}
lid.write(LID_CLOSED_ANGLE);
delay(500); // let the lid settle before re-sensing
nearCount = 0;
}
delay(60);
}

We added two small features most versions skip. The lid only opens after two close readings in a row, which stops random echoes from flapping it, and it stays open while your hand is still there. Three settings at the top let you tune it:
|
Setting |
Default |
Change it when |
|
OPEN_DISTANCE_CM |
20 |
The lid opens too early or too late |
|
LID_OPEN_ANGLE |
100 |
The lid does not open fully, or swings too far |
|
HOLD_OPEN_MS |
3000 |
You want the lid to stay open longer or shorter |
Step-by-step assembly
-
Upload the code and test everything on the table first. Wave a hand at the sensor and check that the servo turns.
-
Fix the servo to the back wall of the bin, just below the hinge, with a glue gun or double-sided tape.
-
Glue an ice-cream stick to the servo horn and the other end to the underside of the lid, close to the hinge. This stick is what pushes the lid up.
-
Glue a small cardboard shelf to the front wall, just below the rim, and stick the half breadboard on it.
-
Clip the sensor into its holder and plug its pins into the breadboard so the two round transducers face forward, not up.
-
Tape the Uno and power bank to the side wall near the front so the 20 cm jumpers reach both the breadboard and the servo.
-
Wire everything as per the table above, plug in the power bank and test with your hand at different distances.

If the lid jams, the stick is usually too far from the hinge. Move it closer and the servo needs less force to lift it.
Making it better: full-bin alert, solar power
Full-bin alert. Fix a second HC-SR04 inside the bin just under the rim, facing down, and connect an active buzzer module to D7. When the waste comes within 8 cm of the rim, the buzzer sounds. Add this to the main sketch:
// Full-bin alert: add above setup() in the main sketch
const int FILL_TRIG = 6; // second HC-SR04, inside the rim, facing down
const int FILL_ECHO = 5;
const int BUZZER_PIN = 7; // add pinMode(BUZZER_PIN, OUTPUT); in setup()
const int FULL_CM = 8; // waste within 8 cm of the rim = bin is full
// also add pinMode(FILL_TRIG, OUTPUT); and pinMode(FILL_ECHO, INPUT); in setup()
void checkFull() { // call checkFull(); at the start of loop()
long fill = readDistanceCm(FILL_TRIG, FILL_ECHO);
digitalWrite(BUZZER_PIN, (fill > 0 && fill <= FULL_CM) ? HIGH : LOW);
}
If the buzzer beeps all the time, your module is active-low: swap HIGH and LOW.
Solar power. A mini epoxy solar panel on the lid is a strong talking point for the green-energy angle. Its output is too small to drive the servo directly, so present it as charging a rechargeable battery through a charging module, not as the main power supply.
Heavier lid. If you are using a real plastic bin, swap the SG90 for an MG90S metal gear servo. It uses the same wires and the same code.
|
For heavier lids. Drop-in swap for the SG90. |
Sounds the full-bin alert. |
Mini Epoxy Solar Panel 70x70 mm Adds a solar-charging demo. |
Explaining it at the exhibition
Judges often have only a minute or two at each table, so open with one line. Then walk through sense, decide and act using the block diagram.
-
Show the numbers. Keep a laptop running the Serial Monitor so judges can see the distance change as they move their hand.
-
Answer "why ultrasonic?" It measures actual distance and is not affected by colour or room light the way a simple IR sensor can be.
-
Give real uses. Hospitals, kitchens, and public toilets, where touch-free bins cut the spread of germs. It also fits neatly with Swachh Bharat themes.
-
Carry spares. Bring a fully charged power bank, a 9V battery as a last resort, and a printed copy of the circuit diagram.
Want something different for next year? Browse our sensor-based project ideas for students.
Ready to build your smart dustbin?










