SMART DUSTBIN

Introduction

It is a DIY smart dustbin using Arduino, ultrasonic sensor, and a servo motor. After the recent covid-19 era, people are trying to adopt a more contact-less approach. Our smart dustbin uses one such approach.

Components

Before you start building your Arduino-based drone, make sure you have the following components:

Arduino UNO

Ultrasonic sensor HC-SR04

SG-90 micro servo motor

Dustbin

Jumper wires

Battery

Circuit diagram

Working

The smart dustbin utilizes an Ultrasonic sensor HC-SR04 for object detection in its proximity. Once an object is detected, the sensor sends a signal to the Arduino Uno. The Arduino processes this signal and subsequently sends a command to the Servomotor to open the top flap of the dustbin.

To customize the duration for which the flap remains open, you can easily adjust the code within the Arduino IDE. By making minor modifications to the code, you can change the open duration to your desired value. For instance, if you wish to have the flap open for a different duration, you can simply update the code accordingly.

Code

#include // Include the servo library

Servo servo; // Create a servo object

int trigPin = 5; // Define the trigger pin for the ultrasonic sensor

int echoPin = 6; // Define the echo pin for the ultrasonic sensor

int servoPin = 7; // Define the pin for controlling the servo motor

int led = 10; // Define an LED pin for reference

long duration, dist, average; // Variables for distance measurements

long aver[3]; // Array for averaging

void setup() {

Serial.begin(9600);

servo.attach(servoPin); // Attach the servo to its pin

pinMode(trigPin, OUTPUT); // Set trigger pin as an output

pinMode(echoPin, INPUT); // Set echo pin as an input

servo.write(0); // Close cap on power on

delay(100);

servo.detach();

pinMode(led, OUTPUT); // Set the LED pin as an output

}

void measure() {

digitalWrite(led, HIGH); // Turn on the LED as an indicator

digitalWrite(trigPin, LOW); // Set the trigger pin low

delayMicroseconds(5); // Short delay

digitalWrite(trigPin, HIGH); // Set the trigger pin high

delayMicroseconds(15); // Short delay

digitalWrite(trigPin, LOW); // Set the trigger pin low again

pinMode(echoPin, INPUT); // Set echo pin as an input

duration = pulseIn(echoPin, HIGH); // Measure the pulse duration

dist = (duration / 2) / 29.1; // Calculate the distance

}

void loop() {

for (int i = 0; i <= 2; i++) { // Take three distance measurements for averaging

measure();

aver[i] = dist;

delay(10); // Delay between measurements

}

dist = (aver[0] + aver[1] + aver[2]) / 3; // Calculate the average distance

if (dist < 50) { // Change distance threshold as per your need

servo.attach(servoPin); // Attach the servo

delay(1);

servo.write(0); // Open the flap

delay(3000); // Keep the flap open for 3 seconds

servo.write(150); // Close the flap

delay(1000); // Additional delay for flap closure

servo.detach(); // Detach the servo

}

Serial.print(dist);

}