TechieYan Technologies


Smart Dustbins - Embedded SYstems


The main purpose of this smart dustbins (garbage segregation ) project is to automate a dustbin so as to acquire a clean and tidy environment. With an automatic lid open and close mechanism one can avoid going very near to the dustbin and can avoid touching it, which helps to prevent one from acquiring disease and germs. To  achieve the output here we used a  microcontroller interfaced with an ultrasonic sensor and a servo motor. In the existing system, one has to open the lid of the dustbin with certain means but in the proposed system the lid of the dustbin will be automatically opened with the help of a servo motor when an ultrasonic sensor senses a human or something in front of it within the range. This would be taken as a step forward towards smart and clean. Dustbins are segregated into different categories like blue-colored dustbins for dry waste and green-colored dustbins for wet waste and one dustbin for hazardous waste where electrical components like batteries and industrial wastes are dumped. Despite having these separations and well management of waste, countries like India are lacking proper cleanliness around garbage dumping spots which indeed are leading to cause deadly diseases like asthma, birth defects, cancer, cardiovascular disease, and infectious diseases like malaria, typhoid, etc. animals like street dogs, cows and buffalos would be affected by eating the leftovers in the garbage. More features and applications can be added to this simple smart dustbin to make the system more effective by micromanagement.


In contrast to the rapidly increasing population the amount of garbage or waste produced on daily bases is also increasing. The dustbin is one of the tools used to store and collect garbage in domestic as well as industrial outlets. In contrast to the rapidly increasing population, the amount of garbage or waste produced on daily bases is also increasing.

A smart  dustbin will  help in keeping  the   environment clean(eco-friendly). As We are following  the Swachh Bharat Mission” The Swachh Bharat Abhiyan is the most significant cleanliness campaign by the Government of India”. Nowadays  technologies   are getting smarter day-by-day so, to clean the environment we are designing a smart dustbin using Arduino. This smart dustbin management system is built on a microcontroller-based system having ultrasonic sensors on the dustbin. If dustbin is not maintained then these can cause an unhealthy environment and can cause pollution that affects our health. In this proposed technique we have designed a  smart dustbin using ARDUINO UNO, along with an ultrasonic sensor, servo motor, and battery jumper wire. so, the Dustbin will  open its lid  when someone  is near it, then it will wait for a given time period, then it will close automatically. Here the lid will close when you don’t want to use it and  it will only open when it is required. The  aim of this project  is also to make it cost-effective so that many people can benefit from this. And it should be usable to anyone and helpful for them. The advantage of this project is that it maintains environmental hygiene and also helps in bringing evolution by technology in terms of cleanliness.


Components Required

Hardware Requirements

  • Arduino Uno :

    Arduino Nano is a microcontroller from Arduino Family, a friendly board based on the ATmega328. Nano has 22 Input/Output pins. 14 are digital pins and 8 are analog pins.

For more details,  pinout and datasheet, you can visit:

  • Ultrasonic sensor (HC-SR04): It is a SONAR-based distance measurement sensor. It provides excellent non-contact range detection from 2 cm to 400 cm with high accuracy and reliable readings.
  • Servo Motor – SG90: It is very small and lightweight with a high-performance servo motor. Works on 5V power supply. The Servo Motor rotates 180 degrees approximately.  

Software Requirements

  • Arduino Ide : Arduino IDE (Integrated development environment) is software that is used to dump the program into boards. Arduino- IDE’s major use is to build electronics-related projects. Arduino is an open-source platform simple and easy-to-understand platform for coding. 


Block diagram

In the following block diagram the ultrasonic sensor is an input device and the servo motor is the output device interfaced with Arduino nano. Here Arduino nano will act as a controller which will send and receive the information. The ultrasonic sensor sends the information to the Arduino nano and the servo motor receives the information from the Arduino Nano.

smart dustbin block diagram

Flow Chart

A flowchart is a diagram that shows a process’ individual steps in their proper order, similarly the following flowchart tells about the steps involved in the project and the sequential flow of the code also.

So as it starts, first, the ultrasonic sensor calculates the distance and checks whether the distance is less than a certain limit or whether a person is near the dustbin or not. If yes, the servo rotates to open the bin, and if no, it goes back to check the distance again and again.

Smart dustbin Flow chart

*website used to make Flow Chart and Block Diagram :

Pin Connections

Ultrasonic sensor 

The following pin connection is about the connection of ultrasonic pins with Arduino Nano. The Ultrasonic Sensor has 4 pins Vcc, Trig(Trigger), Echo & Ground. The Vcc pin of ultrasonic is connected to 5V of Arduino Nano, Trig is connected to D3, Echo is connected to D2, and Ground(GND) is connected to GND(you can use any ground pin of the board) of Arduino Nano, as shown in figure

Smart Dustbin Pin connections


The following pin connection is about the connection of servo motor pins with Arduino nano.  The servo has 3 wires, Brown, Red, and Orange which are Ground, Power(+5V), and PWM(or you can say input ) respectively. The brown wire is connected to the GND(you can use any ground of board) of Arduino Nano, Red is connected to the VIN of Arduino Nano and Orange is connected to A0(Analogue pin), as shown in figure

smart dustbins servo pin connections

Circuit diagram

The following circuit diagram describes the connection between the devices with a microcontroller “Arduino Nano” here RED color wire used for VCC and the BLACK wire is used for GND and BLUE and YELLOW wire is used as echo and trigger pin for ultrasonic sensor and YELLOW wire of Servo is Connected to A0. 

smart dustbins circuit diagram

Smart Dustbin Circuit Diagram 

Now connect the Arduino Nano with your computer/laptop using USB A to MINI B cable and dump the code.

Cable For Arduino Nano USB A to MINI B (Nickel Plated Connector)-1.2 M. Credit:

Cable For Arduino Nano USB A to MINI B (Nickel Plated Connector)-1.2 M. Credit:


The next step after setting up the connection is to upload code to Arduino Nano and power it. When the system is turned on, Arduino continues to watch for anything that comes within a certain distance of the ultrasonic sensor. When an object is detected by an ultrasonic sensor, such as a hand or another object, Arduino measures its distance; if it is less than a certain value, the servo motor activates and opens the dustbin Lid. The lid will open for a predetermined period of time before closing on its own.


Here, we’re going to change things in an adaptive direction toward cleanliness. Smart dustbins are far superior to conventional trash bins because of their intelligent waste monitoring and trash compaction technologies. It is furnished with intelligent gadgets like sensors, Arduino, etc. When an object approaches the trash can, the lid automatically opens, and it automatically closes after a predetermined amount of time. In the future, the bin will alert when it is full using some sensors, and with IoT, we can also track it online. 


Working Code

#include <Servo.h>                //Using the Arduino as the controller device,the library enables to control the servo motor
Servo myservo;                    //initialize a servo object to control a servo 

int pos = 0;                      //initization position of servo motor 
int trigPin = 3;                  //ultasonic trig pin is connected to pin 3 of Arduino Nano
int echoPin = 2;                  //ultasonic echo pin is connected to pin 2 of Arduino Nano

int duration;                     //integer duration is created for store the value from ultrasonic sensor 
int distance;                     //integer distance is created for store the value from ultrasonic sensor 

void setup() 
  Serial.begin(9600);             // Initiate a serial communication with baud rate of 9600
  myservo.attach(8);              // servo pin is connected to the pin 8 of arduino nano
  pinMode(trigPin, OUTPUT);       // select ultrasonic pin as a output pin
  pinMode(echoPin, INPUT);        //select ultrasonic pin as a input pin 
  myservo.write(pos);             //initial position of servo 

void loop() 
   ultrasonic();                  //calling ultrasonic function 
  if (distance < 27)              //condition applying 
    myservo.write(pos+90);        //as per the readings of ultrasoinc sensor servo changes the pos 
      myservo.write(pos);        //as per the readings of ultrasoinc sensor servo changes the pos 

//Function for ultrasonic sensor  
void ultrasonic()
  digitalWrite(trigPin, LOW);      // Clears the trigPin condition
  digitalWrite(trigPin, HIGH);     // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, LOW);      // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);// Calculating the time
  distance = 0.034*(duration/2);   // Calculating the distance

If You Face Any Issue Feel Free To Contact us Any Time.

+91 7075575787