This project creates a hands-free smart dustbin using Arduino.
It uses an ultrasonic sensor to detect motion and a servo motor to automatically open and close the lid, making waste disposal hygienic and convenient.
Perfect for beginners in Arduino and electronics!
- The ultrasonic sensor acts as the "eyes" of the dustbin.
- When it detects an object within 15β20 cm, it signals the Arduino Uno.
- The Arduino controls the servo motor to rotate and open the lid.
- After a short delay, the lid closes automatically.
- Arduino Uno β The brain of the project
- HC-SR04 Ultrasonic Sensor β Measures distance using sound waves
- SG90 Servo Motor β Opens and closes the lid
- Jumper Wires β For connections
- Power Source β USB or battery pack
- Dustbin β With hinged lid
- Cardboard/Plastic β To mount components
#include Servo.h Include servo library
Servo servoMotor;
int trigPin = 2;
int echoPin = 3;
int servoPin = 9;
long duration, distance;
void setup() {
servoMotor.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servoMotor.write(10); Close lid on power on
delay(2000);
servoMotor.detach();
}
void measureDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration 2) 29.1; Calculate distance
}
void loop() {
measureDistance(); Measure distance
if (distance 8)
{
servoMotor.attach(servoPin);
delay(1);
servoMotor.write(80); Open the lid
delay(4000); Wait for 4 seconds
servoMotor.write(170); Close the lid
delay(4000);
servoMotor.detach(); Detach the servo
}
delay(50); Delay between measurements
}