Automatic trash-bot

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

Required Components

In order to make this project, you will need the components below. They can  be found here at


Components Photo



Arduino Uno


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.

Setting up the Arduino Uno on Arduino IDE

First you need to set up your microcontroller on Arduino IDE, you can check this Link.


Building the Circuit

  • Servo data (yellow) to pin 3 of Arduino
  • Servo VCC (red) to 5v of Arduino
  • Servo ground (black/grey) to Arduino Gnd
  • Sonar sensor trig to Arduino 6
  • Sonar sensor echo to Arduino 5
  • Vcc to Arduino 5v
  • Gnd to Arduino Gnd
  • 9V Battery connected to Arduino Uno

Programming the Arduino

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); 
void loop()
{       int duration, distance;
digitalWrite(trigPin, HIGH); 
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) {
} else {
// Waiting 60 ms won't hurt any one

Placing the parts to the trash bin

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.

Working Video


Skriv kommentar!

Relevante produkter

TS101 digital loddekolbeTS101 digital loddekolbe i hånd
TS101 digital loddekolbe med USB C forsyning
Tilbudspris Fra 699,00 kr
14 på lager
TS80P USB-C Loddekolbe kitTS80P Loddekolbe
TS80P USB-C Loddekolbe kit
Tilbudspris Fra 799,00 kr
1 på lager
bruge Loddekolbe Renser til at rengøre loddekolbespidsenLoddekolbe Renser
Luksus Loddekolbe renser
Tilbudspris 89,00 kr
8 på lager