How to Make a Smart Dustbin Using Arduino Uno, Servo Motor and an Ultrasonic Sensor
Introduction
In this tutorial, we will learn how to make a smart dustbin using Arduino Uno, Servo motor and an ultrasonic sensor. This project introduces a touchless solution for waste disposal, which is particularly useful in maintaining hygiene during the COVID-19 era and beyond.
Hardware Required
Software Required
Component Details
1. Arduino Uno
Arduino Uno is an open-source microcontroller board based on the ATmega328P processor. Key features include:
It is economical and ideal for beginner-level projects, allowing users to experiment freely without worry.
2. Ultrasonic Sensor HC-SR04
The HC-SR04 sensor measures distance using SONAR principles.
3. SG90 Micro Servo Motor
The SG90 is a lightweight, fast, and reliable servo motor, commonly used in:
Working Concept
The smart dustbin automates the process of opening the lid when an object is detected. Here's how it works:
1. Detection: The ultrasonic sensor HC-SR04 detects an object in front of the dustbin.
2. Signal Processing: The sensor sends data to the Arduino Uno, which processes the signal.
3. Actuation: The Arduino signals the servo motor to open the dustbin lid for a specified time (default: 3 seconds).
This project provides a contactless solution, making trash disposal more hygienic and efficient.
Circuit Diagram
The main components of the circuit are:
1. Arduino Uno
2. Ultrasonic Sensor HC-SR04
3. SG90 Servo Motor
Connections:
Program Code
Here’s the code for the smart dustbin. Upload it to the Arduino Uno using the Arduino IDE.
#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 averaging distance measurements
void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); // Close the lid on startup
delay(100);
servo.detach();
}
void measure() {
digitalWrite(led, HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
dist = (duration / 2) / 29.1; // Calculate distance
}
void loop() {
for (int i = 0; i <= 2; i++) { // Average distance calculation
measure();
aver[i] = dist;
delay(10);
}
dist = (aver[0] + aver[1] + aver[2]) / 3;
if (dist < 50) { // Change threshold distance as needed
servo.attach(servoPin);
delay(1);
servo.write(0); // Open the lid
delay(3000); // Keep it open for 3 seconds
servo.write(150); // Close the lid
delay(1000);
servo.detach();
}
Serial.print(dist);
}
Final Assembly
1. Attach the Arduino Uno and the 9V battery to the dustbin wall using double-sided tape.
2. Upload the code to the Arduino board via the Arduino IDE.
3. Power on your setup, and your smart dustbin is ready to use!
Conclusion
With this smart dustbin, you have created a hygienic and contactless solution for waste disposal. Experiment further by customizing the code to adjust lid timings or sensor sensitivity. Enjoy building!