Introduction
A smart dustbin is an automatic waste bin that opens its lid when a person brings their hand or an object close to it.
In this project, we will use an Arduino UNO, an HC-SR04 ultrasonic sensor, and a servo motor to create a simple touch-free automatic dustbin.
The ultrasonic sensor detects the distance between the user's hand and the sensor. When the detected distance becomes smaller than a predefined value, Arduino commands the servo motor to open the lid.
Working sequence
Hand approaches sensor
↓
HC-SR04 detects
↓
Arduino reads
distance
↓
Distance < threshold?
↙ ↘
YES NO
↓ ↓
Open lid Keep closed
↓
Wait
↓
Close lid
Block Diagram
┌────────────────────┐
│ User's Hand │
└─────────┬──────────┘
↓
┌────────────────────┐
│ HC-SR04 │
│ Ultrasonic Sensor │
└─────────┬──────────┘
│
Distance
↓
┌────────────────────┐
│ Arduino UNO │
│ Microcontroller │
└─────────┬──────────┘
│
Control Signal
↓
┌────────────────────┐
│ Servo Motor │
└─────────┬──────────┘
↓
┌────────────────────┐
│ Dustbin Lid │
└────────────────────┘
Hardware Requirements
| Component | Quantity | Purpose |
|---|---|---|
| Arduino UNO | 1 | Main controller |
| HC-SR04 Ultrasonic Sensor | 1 | Detects hand/object |
| Servo Motor | 1 | Opens/closes lid |
| Breadboard | 1 | Prototyping |
| Jumper Wires | As required | Connections |
| Dustbin/container | 1 | Project body |
| USB Cable | 1 | Arduino programming |
| External 5V supply | Optional | Servo power |
Circuit Diagram
ARDUINO UNO
┌──────────────────┐
│ │
D9 ───┤ │
D10 ───┤ │
D6 ───┤ │
│ │
5V ───┤ │
GND ───┤ │
└───────┬──────────┘
│
┌──────────────┴─────────────┐
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ HC-SR04 │ SERVO │
│ │ │
│ TRIG ← D9 │ │ Signal ← D6 │
│ ECHO → D10 │ │ VCC │
│ VCC → 5V │ │ GND │
│ GND → GND │ └─────────────┘
└─────────────┘
Arduino Code
#include <Servo.h>
const int trigPin = 9;
const int echoPin = 10;
const int servoPin = 6;
Servo lidServo;
long duration;
int distance;
const int detectionDistance = 20;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lidServo.attach(servoPin);
lidServo.write(0);
Serial.begin(9600);
}
void loop() {
distance = getDistance();
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance > 0 && distance <= detectionDistance) {
lidServo.write(90);
delay(3000);
lidServo.write(0);
delay(500);
}
delay(100);
}
int getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, 30000);
if (duration == 0) {
return -1;
}
return duration * 0.034 / 2;
}
Conclusion
The Arduino smart dustbin is a simple and practical automation project that demonstrates how sensors, microcontrollers and motors can work together.
The HC-SR04 detects the user's hand, Arduino processes the distance information, and the servo motor automatically opens and closes the lid.
With additional sensors and a Wi-Fi-enabled controller, this basic project can be expanded into a more advanced smart waste-management system.