Ultrasonic Sensor-Activated Trash Bin

Introducing an “Ultrasonic Sensor-Activated Trash Bin” project that transforms your conventional waste disposal into a seamless, touchless experience. The core of this innovation lies in an Arduino-powered system featuring an ultrasonic sensor (HC-SR04) and a servo motor.
As someone approaches, the ultrasonic sensor detects their presence and triggers the servo motor, opening the trash bin lid. After a brief interval, the lid gracefully closes, ensuring effortless waste disposal while maintaining cleanliness.
The circuit incorporates the Arduino board, ultrasonic sensor, and servo motor. Connect the ultrasonic sensor’s Trig and Echo pins to digital pins 9 and 10, respectively. The servo motor attaches to digital pin 7 for precise control.
A transistor (NPN) manages the motor, with its base linked to a resistor (1k ohm) and then to digital pin 7. The transistor’s collector connects to the motor’s positive terminal, and the emitter connects to ground. Additionally, a diode (1N4007) safeguards against back electromotive force (EMF).
Component List:
Name | Quantity | Component |
---|---|---|
U1 | 1 | Arduino Uno R3 |
DIST1 | 1 | Ultrasonic Distance Sensor |
SERVO1 | 1 | Positional Micro Servo |

Arduino Code:
#include <Servo.h>
Servo servo; // Create a Servo object to control the lid
#define trig 2 // Ultrasonic sensor trigger pin
#define echo 3 // Ultrasonic sensor echo pin
int distance; // Variable to store the distance measured by the ultrasonic sensor
void setup() {
servo.attach(9); // Attach the servo motor to pin 9
pinMode(trig, OUTPUT); // Set the trigger pin as output
pinMode(echo, INPUT); // Set the echo pin as input
}
void loop() {
// Measure the distance to the nearest object
digitalWrite(trig, LOW); // Set the trigger pin to LOW
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(trig, HIGH); // Set the trigger pin to HIGH
delayMicroseconds(10); // Wait for 10 microseconds
digitalWrite(trig, LOW); // Set the trigger pin to LOW
// Measure the time it takes for the echo pulse to return
long duration = pulseIn(echo, HIGH);
// Calculate the distance to the nearest object
distance = (duration / 2) / 29.1; // Distance in centimeters
// If the distance is less than 200 centimeters, open the lid
if (distance < 200) {
servo.write(0); // Open the lid
} else {
servo.write(90); // Close the lid
}
// Wait for 100 milliseconds
delay(100);
}
The Ultrasonic Sensor-Activated Trash Bin project showcases the fusion of technology and everyday convenience.
By incorporating automation into waste disposal, it not only simplifies tasks but also promotes a cleaner and more hygienic living environment. This project stands as a testament to the practical applications of Arduino-based systems in enhancing our daily routines.