LEARNSmart dustbin using arduino, ultrasonic sensor in 2$

Smart dustbin using arduino, ultrasonic sensor in 2$


As the population is increasing day by day so the pollution is increasing which is directly related to the population. As we can see an increase in the garbage around urban areas as well as rural areas. So for this purpose, we have implemented a smart dustbin that works automatically without human interaction, it distributes to this problem and helps to solve the issue of land pollution. This project is based on sensor-based circuitry which works automatically.

smart dustbin
Smart Dustbin

In this project a simple and easy technique is shown to make this smart dustbin using Arduino, which will cost around 2$; This smart dustbin works automatically, which open up when approaching with some garbage nearby to the sensor.

The components which are used in this project are the Hc-04 ultrasonic sensor and the servo motor, which is discussed intensely.


Usually, dustbins require human interaction to be opened up by pushing its button with the feet, which pulls the head of the dustbin and then throw garbage into it. Also, it’s a big challenge for normal dustbins to track either it’s full or empty so that waste should not be overflowing and helps the user. This technology helps everyone, as it cost around 1$ to 2$ and works all by itself.


The smart dustbin project consists of a sensor to detect human legs, hands whatever it detected, the sensor will automatically generate a signal, and will open automatically without anyone help to press its lever. As the name implies smart dustbin, which opens automatically; when it receives the signal and locks after a few seconds own it’s own, this is programmed in such a way that it closes after 4 to 5 seconds,  it can also be set according to user’s need. The dustbin consists of a smart circuitry using Arduino. This facility will help to empty the particular garbage bin as well. This dustbin is very helpful and has many applications in offices, homes, and even in city places where there is high population rate. This project is made to protect our environment and the clean green world.  This dustbin works fully automatically.


Dustbins, Garbage bins or Trash Cans, whatever you call them are small plastic or sometimes metal containers that are used to store trash or waste on a temporary basis. They are usually spotted at homes, offices, streets, parks, etc. to accumulate waste. In some areas, the government has placed waste containers for the public use, which is the only way to overcome pollution, as it causes a lot of problems, but whatever the case is, this is the only solution to keep the garbage stored. This project is constructed with a simple system called Smart Dustbin using Arduino, Ultrasonic Sensor, and Servo is also inserted, which open the head of the dustbin automatically without human interaction.



The concept behind Smart Dustbin using Arduino;

Ultrasonic sensor and servo motor play a vital role in the field of electronic engineering. The idea is used on the back inside the smart dustbin using the Arduino, which is an object detection device, that is quite easy to implement. Ultrasonic Sensor is already used in Object Avoiding Robot, where a smart car detects an object and the Robot will change its position automatically when an item is placed in its way. The same technique is performed in this project, where the Ultrasonic Sensor is placed on top of the dustbin, and when the sensor detects an object like a human hand, it will trigger Arduino to open the head.

Components Required for Smart Dustbin;

The following components are used in the project, which is easily available.

  • Arduino Uno
  • Servo motor
  • Ultrasonic Sensor
  • Dustbin or Container
  • Jumper wires

The step by step process is explained in the procedure category.

Circuit Diagram;

The circuit diagram is shown below and the wiring is also discussed in the procedure section as well.

Smart dustbin
Circuit Diagram
Note:  Step by step procedure is given below. Make sure to have the exact components given above to make smart dustbin.

Code Of Arduino;

[php] //define Pins
#include <Servo.h>

Servo servo;

int trigPin = 9;
int echoPin = 8;

// defines variables
long duration;
int distance;

void setup()

// Sets the trigPin as an Output
pinMode(trigPin, OUTPUT);
// Sets the echoPin as an Input
pinMode(echoPin, INPUT);
// Starts the serial communication
void loop()
// Clears the trigPin
digitalWrite(trigPin, LOW);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print(“Distance: “);
if ( distance <= 25 ) // Change Distance according to Ultrasonic Sensor Placement




The process to make Smart dustbin;

At first, set up all the components to build a smart dustbin using Arduino. First of all, take a start from the Arduino Uno then Motor and know about how to program the machine to open the head of the smart dustbin. If you are thinking about implementing the idea of how to open the head or box of the dustbin using a servo motor follow the steps carefully.

Step 1:

Take start from a simple Arduino, which is following and make sure to use the same coding, attached in the Article.

Arduino uno
Arduino UNO

Step 2:

Ultrasonic Sensor
Ultrasonic Sensor

Now follow the steps below.

  • Connect the ground pin to the ground of the Arduino.
  • Connect the Vcc pin to the 5v(Vcc) of Arduino.
  • Connect the Trig pin to 9 pins of Arduino.
  • Connect the Echo pin to 8 pins of Arduino.

Step 3:

As the servo motor plays an essential role in opening the lid of the dustbin, this Motor can easily maintain a fixed angle to move without any hassle.

Servo motor
Servo Motor

Follow the steps for connecting to the Arduino.

  • The red pin of the servo motor is attached to the Vcc of Arduino.
  • The black pin of the servo is the ground pin.
  • The orange pin or yellow(signal pin), as shown in the circuit diagram, is attached to the seven pins of Arduino.

Step 4:

After wiring as instructed, now fix the ultrasonic sensor on the dustbin, as shown in the figure below.

Ultrasonic sensor
Placing the Ultrasonic Sensor

Now drill holes in the dustbin according to the fixed dimension as shown below.

Ultrasonic sensor
WARNING: It needs force to drill holes and makes sure that the drill has a sharp knock.

Now fix the ultrasonic sensor, as shown below.

Ultrasonic sensor
Fixing the Ultrasonic Sensor

Step 5:

Now glue the Servo motor so that it can be fixed permanently.

Servo motor
Glue the Servo Motor
Servo motor
Mechanism of Servo Motor
Note: As according to the law of physics, if you want to push something, you will need more energy from the mean up to the extreme value. Just like when you open the door and then close it with the help of a motor. If you want to open this door with the help of servo, you have to place this servo motor with the arm of the dustbin, as shown above.

Step 6:

Connect the battery, as you can connect 5v battery as well. In my case, I have attached a 9v battery.

9v Battey
Connecting Battery

Now if everything is done accordingly. Test the circuit to check whether it’s working fine or not.

Smart dustbin
Testing of Smart Dustbin

Working of smart dustbin;

When everything is done, now set the dustbin to achieve maximum efficiency when every necessary connection is made. Then upload the code to the Arduino which is attached at the code section, after uploading the code to Arduino. Now give power to Arduino you can also use a 5 volts power supply. Still, in my case, I have used a 9v battery, which is attached to the circuit. When the circuit is ON, Arduino will be started and the sensor will continuously work under process to detect an object nearby.  If any object is found it will give a signal to Motor.


Suppose if the ultrasonic sensor detects a hand or a leg of a human being or any other object placed nearby, then Arduino will measure the distances, if the distance is less than the predefined value then the Motor will be activated and Arduino servo motor will be starts and hence the head of the dustbin will be opened which is attached with the servo motor.

After a few seconds, it will automatically close because the predefined value is given, it can easily be changed.


This device has a wide range of application some of them are as following;

  • The smart dustbin is used in offices to store a vast amount of papers.
  • It occupies less space so that it can be easily used in homes.
  • It is low-cost everyone can easily implement it in their houses and offices.
  • It also plays an essential role in public places.
  • After completion of this project, you will be able to make our new project obstacle avoiding Robots.


It’s a very simple and easy to implement a Smart dustbin project which works with the help of Arduino. When it opens the lid(door) of the dustbin then it automatically closes the lid, it is due to the waste that should not be exposed to the surrounding which creates a bad image as well and it also doesn’t allow flies and other insects to enter the bin. It works fully automatic. You can also work hard to make it more autonomous.


Aizaz khan
Aizaz khanhttps://www.myelectricsparks.com/aizaz-khan/
Aizaz was the first person to get a byline on his blog on technology from his home in Bannu in 2017. Then, he went on to a career in breaking things professionally at my electric sparks which is where he eventually took over the kit as a hardware editor. Today, as the senior editor of hardware for my electric sparks, he spends time reporting about the most recent developments in the hardware industry and technology. If he's not reporting on hardware or electronics, you'll see him trying to be as remote from the world of technology as possible through camping in the wild.


Please enter your comment!
Please enter your name here

Latest news

About Tech

You might also likeRELATED
Recommended to you