Smart Dustbin

Do you want to turn your old dutbin to a smart dustbin?


Let’s upgrade our old dustbin to smart dustbin by making it open when it detects our hands and play a music!


This video will show you how to make a smart dustbin using a Maker UNO, ultrasonic sensor and micro servo.

Hardware Preparation

This is the hardware connection and the components needed.

Sample Code


#include <Servo.h> // Include the Servo library
#define SERVO 3
#define TRIGPIN 12
#define ECHOPIN 11
#define PIEZO 8
Servo myServo; // Create a servo object
int val = 0;
long duration;
long distance;
#define NOTE_G4 392
#define NOTE_C5 523
#define NOTE_G5 784
#define NOTE_C6 1047
int openMelody[] = {NOTE_G5, NOTE_C6};
int openNoteDurations[] = {12, 8};
int closeMelody[] = {NOTE_C6, NOTE_G5};
int closeNoteDurations[] = {12, 8};
#define playOpenMelody() playMelody(openMelody, openNoteDurations, 2)
#define playCloseMelody() playMelody(closeMelody, closeNoteDurations, 2)
char inChar;
String inString;
void setup() {
pinMode(TRIGPIN, OUTPUT); // Sets the trigPin as an Output
pinMode(ECHOPIN, INPUT); // Sets the echoPin as an Input
void loop() {
digitalWrite(TRIGPIN, LOW);
digitalWrite(TRIGPIN, HIGH);
digitalWrite(TRIGPIN, LOW);
duration = pulseIn(ECHOPIN, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance = duration * 0.017; // Calculating the distance
if (distance < 10 ) {
else { //Check data
void playMelody(int *melody, int *noteDurations, int notesLength)
for (int thisNote = 0; thisNote < notesLength; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIEZO, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
view raw SmartDustbin.ino hosted with ❤ by GitHub

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
Tutorials of Cytron Technologies Scroll to Top