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

Send Data to Firebase Using Arduino Uno WiFi Rev2
Simple Alarm System Using Maker Nano
Program Cucumber ESP32-S2 Using CircuitPython
Face Recognition Using OpenCV on Raspberry Pi 400
Turned Your Tablet as a Display for the Raspberry Pi 400
Scroll to Top