0% found this document useful (0 votes)
35 views17 pages

Smart Dustbin Using Arduino and Ultrasonic Sensor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views17 pages

Smart Dustbin Using Arduino and Ultrasonic Sensor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

Home (/) / Microcontroller Based Projects (/microcontroller-projects)

/ Smart Dustbin using Arduino and Ultrasonic Sensor

Smart Dustbin using Arduino and Ultrasonic Sensor

Published January 24, 2025 0

Naveed Zahid Hussain


N
Author

Arduino Smart Dustbin using Ultrasonic Sensor


Smart Dustbin as its name represents its work smartly or we can say that it is an automatic
dustbin. Smart Dustbin is a very good project from the Arduino
(https://circuitdigest.com/arduino-projects). We can say that It is a decent gadget to make your
home clean and attractive. kids spread trash to a great extent by paper, rappers and numerous
different things at home. They will have fun with this dustbin they play with the dustbin and in the
play of them, they clean your home as well because every time they use the smart Dustbin and it
attracts the kids. They generally will be utilized to throw all trash and waste into this smart

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 1/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

dustbin. if your hands are full of trash or junk and you're unable to open it manually this can be
used. As it opens automatically without touching, this can help to control the spread of
Coronavirus and even mosquitoes will not move around it so that it helps from preventing the
spread of new diseases. Previously, We have also built IoT Based Dumpster Monitoring using
ESP8266 (https://circuitdigest.com/microcontroller-projects/iot-garbage-monitoring-using-
arduino-esp8266) and IoT Smart Dustbin using NodeMCU
(https://circuitdigest.com/microcontroller-projects/iot-based-smart-dustbin-management-
system).

Table of Contents
Component Requirement for Arduino Based Dustbin

Project Hardware Software Selection

Block Diagram

Circuit Diagram 
 

Smart Dustbin Arduino Code Explanation

Other Smart Dustbin Projects

Component Requirement for Arduino Based Dustbin



The following are the components required to build a smart dustbin using Arduino. 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 2/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor


 


Project Used Hardware 
 


Arduino UNO, 
 


Jumper Wires, 
 


Servo Motor, 
 


Ultrasonic Sensor 
 


Project Used Software 
 


Arduino IDE 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 3/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

Project Hardware Software Selection



Arduino UNO: As you know that Arduino is a microcontroller-based open source electronic
prototyping board that can be programmed with an easy-to-use Arduino IDE. The UNO is one of
the most popular boards in Arduino family and a great choice for beginners. 
 


Ultrasonic Sensor: These are the sensor that use ultrasonic waves to detect objects or to measure
the distance between themselves and the object 
 


Servo Motor: This is an electrical device that can push or pull and also rotate an object with great
precision. if you want to rotate an object at some specific angles or distance, then you use servo
motor. It is made up of a simple motor that runs through a servo mechanism. We can get a very
high torque servo motor in a small and light weight packages. 
 

Block Diagram

The working of this Arduino smart dustbin is very simple. The ultrasonic sensor acts as the input
and the servo motor acts as the output, the Arduino UNO microcontroller is the main brain
behind the project. The block diagram for Arduino smart dustbin is shown below 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 4/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor


As shown in the block diagram, the Arduino microcontroller constantly monitors the values from
the ultrasonic sensor which is placed outside the dustbin. When a person comes near the dustbin
the values from the sensor change, this change is noticed by the microcontroller, and it then turns
the servo motor to open the dustbin. After some time the controller turns the servo again in the
opposite direction to close the dustbin, then the whole process is reapted again. 
 

Circuit Diagram

The image below shows the Arduino circuit diagram for building a smart bin. As you can see it is
very simple, it just has an ultrasonic sensor and a servo motor connected to the Arduino UNO,
and the whole setup is powered by a 9V battery. 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 5/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

(/fullimage?i=circuitdiagram_mic/Smart-Dustbin-Circuit.jpg) 
 


You can make the connections as shown in the circuit diagram, if you have any doubts you can also
follow the connection diagram below 
 

Component Pin Arduino Connection


Servo Motor Yellow Wire Digital Pin 7
Servo Motor Red Wire 5V
Servo Motor Black Wire GND
Ultrasonic Sensor VCC pin 5V
Ultrasonic Sensor GND pin GND
Ultrasonic Sensor Trig pin Digital Pin 5
Ultrasonic Sensor Echo pin Digital Pin 6
9V Battery Positive Vin
9V Battery Negative GND

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 6/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

(https://bit.ly/46pT3RL)

Smart Dustbin Arduino Code Explanation



The code for the Arduino Smart Dustbin is very simple and straightforward. The complete code
for this project can be found at the bottom of this page. But now let's break the code into small
segments to understand how the code works. Starting with library and variable declaration 
 

#include <Servo.h> //servo library


Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average


We have used the Servo.h library to control the servo motor using Arduino. This library is already
pre-installed in Arduino and is very easy to use. If you are completely new to servo motors and
Arduino, you can read our article on how to use servo motor with Arduino
(https://circuitdigest.com/microcontroller-projects/interface-servo-motor-with-arduino). Next,
we have mentioned to which pins our ultrasonic sensor and servo motor is connected to, in this
case trigger pin is connected to pin5, echo pin is connected to pin 6 and servo signal pin is
connected to pin 7 of Arduino UNO. 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 7/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}


Inside the void setup function, we start the serial monitor at 9600 baud rate which will be useful
for debugging. And then initialize the servo motor and declare trigger pin as output pin and echo
pin as input pin. We are also moving the servo motor position to 0, to make sure the dustbin is
closed during power on. 
 

void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}


The above function called measure(), is used to measure the distance between an the dustbin and
the object in front of it. First we turn on the trig pin and wait for 15 microseconds and then turn it
off, this will send the ultrasonic waves out of this sensor which will get deflected back to the
sensor after hitting on the object in front. We will read these ultrasonic waves again using the
sensor by using the echo pin as input. Then calculate the duration and distance using the above
formulae. If you can also read how to use ultrasonic sensors with Arduino
(https://circuitdigest.com/microcontroller-projects/interface-arduino-with-ultrasonic-sensor) if
you are completely new to ultrasonic sensors. 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 8/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<50 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}


Inside the void loop function, we will implement the main logic of our arduino smart dustbin
project. First we use a for loop to measure the distance between the sensor and the object using
the measure function we discussed earlier, this is done three times and all the results are stored
in an array called aver. We then take the average of all three values to calculate the distance. If
this measured distance is less than 50 we will open the dustbin by controlling the servo motor.
After opening we will wait for 3 seconds and then close the dustbin automatically using the servo
motor again. In the code the servo position 0 is used to open the dustbin and position 150 is used
to close the dustbin. 
 

Other Smart Dustbin Projects



Now that you have learnt how to build a simple smart dustbin project using Arduino UNO, you
can checkout the below smart dustbin projects which you can use to enhance your project and
add more features. All projects have clear circuit diagram and code for anyone to easily rebuild. 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 9/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

(https://circuitdigest.com/microcontroller-projects/iot-based-smart-dustbin-management-system)

IoT based Smart Dustbin Management System using NodeMCU
(https://circuitdigest.com/microcontroller-projects/iot-based-smart-dustbin-management-
system) 
 


It gives a real time indicator of the garbage level in a trashcan at any given time. Using that data,
we can then optimize waste collection routes and ultimately reduce fuel consumption. It allows
trash collectors to plan their daily/weekly pick up schedule. The level of dustbin filled or not is
done by using an Ultrasonic sensor or IR sensor. Through an internet app or web page, every truck
driver knew the real time data easily. 
 

(https://circuitdigest.com/microcontroller-projects/smart-dustbin-using-arduino)

Smart Dustbin using Arduino (https://circuitdigest.com/microcontroller-projects/smart-
dustbin-using-arduino) 
 


The core objective of the Arduino Smart Dustbin is to detect the presence and open the dustbin,
later after the trash is put we have to close it.We have put Ultrasonic sensor on top of the
dustbin's cover. So, when the sensor sees something like a person's hand, it tells the Arduino to
open the lid. 
 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 10/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

(https://circuitdigest.com/microcontroller-projects/iot-based-smart-bin)

IoT Based Smart Bin (https://circuitdigest.com/microcontroller-projects/iot-based-smart-
bin) 
 


IoT-Based Smart Bin project features a custom-built IoT system and Firebase database, using the
Arduino Uno R4 WiFi. Dual ultrasonic sensors handle motion and fill-level monitoring, with an
automated lid synced to a Firebase dashboard built on Vite+React for real-time updates. This
solution uniquely integrates our own IoT network for efficient waste management. We’re moving
forward with multi-node testing to enhance scalability and user experience. 
 

 

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 11/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

Complete Project Code


digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
Copy Code
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}
void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<50 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}

Video

How To Make Smart Dustbin |Best Arduino Project

Tags

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 12/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

Contest (/Tags/Contest) India Automation Challenge 2021 (/Tags/India-Automation-Challenge-2021)

Smart Home (/Tags/Smart-Home) Arduino (/Tags/Arduino) Arduino Uno (/Tags/Arduino-Uno)

Servo Motor (/Tags/Servo-Motor) Ultrasonic Sensor (/Tags/Ultrasonic-Sensor)

Have any question related to this Article?

Start a Discussion on: WHATSAPP

(Https://Chat.Whatsapp.Com/L79JMpehN63KCiBPNRwske)

TELEGRAM DISCORD FORUM

(Https://T.Me/Circuitdigest) (Https://Discord.Com/Invite/UXJrFJSWpz) (Https://Circuitdigest.Com/Forums)

Add New Comment

Comment *

 Login to Comment(/user/login?destination=/microcontroller-projects/how-to-make-smart-dustbin-using-arduino)

Sign in with Google(https://circuitdigest.com/user/login/google)

Log in with Facebook(https://circuitdigest.com/user/login/facebook)

Sign in with GitHub(https://circuitdigest.com/user/login/github)

Log in (/user/login?destination=/microcontroller-projects/how-to-make-smart-dustbin-using-
arduino%23comment-form) or register (/user/register?destination=/microcontroller-
projects/how-to-make-smart-dustbin-using-arduino%23comment-form) to post comments

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 13/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

BCU/BPCU/BRU Series AccliMate™ IP67 Sealed USB Cables


(https://rebrand.ly/7lqrku1 )
IP67 sealed USB Type-C® threaded circular cables are ideal for harsh environments

(https://rebrand.ly/7lqrku1 )

S32K312MINI-EVB Evaluation Board for Automotive and Industrial


Designs (https://rebrand.ly/stztjjt )
Bringing low price & Arduino-UNO pin layout to Auto-Grade EVBs for industrial and auto
applications

(https://rebrand.ly/stztjjt )

MCP16701 High-Performance PMIC (https://rebrand.ly/j1eij1k )


Boost efficiency with MCP16701: Compact, reliable DC-DC converter for optimized power
solutions

(https://rebrand.ly/j1eij1k )

G9KB Series High Power PCB DC Relay (https://rebrand.ly/7zm20tp )


Omron's G9KB series supports high current applications with high capacity load ratings

(https://rebrand.ly/7zm20tp
)

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 14/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

Black Plated RF Connectors and Adapters (https://rebrand.ly/88d9ea


)
Industrial plating option with enhanced durability for a variety of harsh environments

(https://rebrand.ly/88d9ea )

1556 Series ABS Plastic Enclosures (https://rebrand.ly/8c9a5f9 )


Hammond’s modern 1556 series enclosures are designed for circuit boards and IoT
equipment

(https://rebrand.ly/8c9a5f9 )

UAM Wi-Fi Triple Band Antennas (https://rebrand.ly/wusqwf6 )


TE Connectivity's UAM Wi-Fi Triple Band Antennas offer a compact alternative for terminal
antennas

(https://rebrand.ly/wusqwf6
)

Automotive PCB Mount Relay - EP1/EP2 Series


(https://rebrand.ly/9s8ekk2 )
KEMET's automotive PCB-mount relays unique structure offers high performance and
productivity

(https://rebrand.ly/9s8ekk2 )

Join 100K+ Subscribers


Your email is safe with us, we don’t spam.

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 15/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

Type your email address Subscribe

Be a part of our ever growing community.

Semicon Media is a unique collection of online media, focused purely on the Electronics
Community across the globe. With a perfectly blended team of Engineers and Journalists, we
demystify electronics and its related technologies by providing high value content to our
readers.

(https://www.facebook.com/circuitdigest/) (https://twitter.com/CircuitDigest)
(https://www.youtube.com/channel/UCy3CUAIYgZdAOG9k3IPdLmw)
(https://www.linkedin.com/company/circuit-digest/)

COMPANY
Privacy Policy (/privacy-policy) Cookie Policy (/cookie-policy)

Terms of Use (/terms-of-use) Contact Us (/contact)

Advertise (/advertise)

PROJECT
555 Timer Circuits (/555-timer-circuits) Op-amp Circuits (/op-amp-circuits)

Audio Circuits (/audio-circuits) Power Supply Circuits (/smps-power-supply-


circuits)

Arduino Projects (/arduino-projects) Raspberry Pi Projects (/simple-raspberry-pi-


projects-for-beginners)

MSP430 Projects (/msp430-projects) STM32 Projects (/stm32-projects-and-tutorials)

ESP8266 Projects (/esp8266-projects) PIC Projects (/pic-microcontroller-projects)

AVR Projects (/avr-microcontroller-projects) 8051 Projects (/8051-microcontroller-projects)

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 16/17
8/30/25, 1:36 PM Smart Dustbin using Arduino and Ultrasonic Sensor

ESP32 Projects (/esp32-projects) IoT Projects (/internet-of-things-iot-projects)

PCB Projects (/diy-pcb-projects) Arduino ESP8266 Projects (/arduino-esp8266-


projects)

All Microcontroller Projects (/microcontroller-


projects)

OUR NETWORK

(https://circuitdigest.com) (https://components101.com) (https://iotdesignpro.com)

Copyright © 2023 Circuit Digest (/). All rights reserved.

https://circuitdigest.com/microcontroller-projects/how-to-make-smart-dustbin-using-arduino 17/17

You might also like