Smart Dustbin

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

Introduction

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

Video

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

Arduino

#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() {
myServo.attach(SERVO);
pinMode(TRIGPIN, OUTPUT); // Sets the trigPin as an Output
pinMode(ECHOPIN, INPUT); // Sets the echoPin as an Input
pinMode(PIEZO, OUTPUT);
}
void loop() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
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 ) {
myServo.write(0);
playOpenMelody();
delay(5000);
playCloseMelody();
}
else { //Check data
myServo.write(90);
delay(15);
}
}
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;
delay(pauseBetweenNotes);
noTone(PIEZO);
}
}
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

micro:bit Quick Start Kit
Design 3D Model Using TinkerCAD and Print
3D Print Lithophane for Hari Raya Aidilfitri
With Raspberry Pi Imager, you can write Raspberry Pi OS and remote SSH easier
3D Printing Pelita Raya
Tutorials of Cytron Technologies Scroll to Top