Choose your country and language
Language
Everything's getting smarter right? So why not your trash bin? This trash bin opens and closes its lid if it sees anything in front of it. You just need to go closer to it and it'll open automatically and will wait for you to feed it then after a certain time it'll close automatically.
Now lets have fun building it :D
In order to make this project, you will need the components below. They can be found here at eBits.dk.
|
Amount |
Components Photo |
Components |
|
1 |
![]() |
Arduino Uno |
|
1 |
![]() |
|
| 1 | ![]() |
Ultrasonic Sensor HC-SR04 |
| 1 | ![]() |
9V battery to 5.5mm DC connector cable |
| 7 | ![]() |
Dupont cables |
| 1 | Trash bin | |
| 1 | 9V Battery |
The trash bin can be made of cardboard or you can use one but the top lid needs to be flat so it is easy for the servo motor to open the lid.
You will need to install Arduino IDE from this Link. With this you can program your Arduino Uno and more other microcontrollers.
First you need to set up your microcontroller on Arduino IDE, you can check this Link.

The code works like this. If it sees anything (literally anything) in a 25 cm range, the servo goes to 50 degrees and hits the upper lid of the bin, so that the upper lid is opened, waits for three seconds, then automatically turns to 160 degrees and then the upper lid gets closed.
#include <Servo.h>
Servo servo;
int const trigPin = 6;
int const echoPin = 5;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(3);
}
void loop()
{ int duration, distance;
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration devided by 29.1
distance = (duration/2) / 29.1;
// if distance less than 0.25 meter and more than 0 (0 or less means over range)
if (distance <= 25 && distance >= 0) {
servo.write(50);
delay(3000);
} else {
servo.write(160);
}
// Waiting 60 ms won't hurt any one
delay(60);
}

The servo motor is placed under the lid, and I added a plastic part to the servo motor so it can open the lid better.

The battery and Arduino are inside the trash bin, and try to have longer cables so when the trash bin has something inside the cables will not detach. And use a trash bag so the Arduino doesn't get dirty.

And lastly the ultrasonic sensor is in front of the trash bin so the sensor will be able to see you when you want to use the trash bin.
Language