0% found this document useful (0 votes)
3 views

Smart Dustbin using Arduino

This document outlines a project to create a Smart Dustbin using an Arduino Uno, an ultrasonic sensor, and a servo motor. It covers the materials needed, circuit connections, and provides detailed code for programming the Arduino to automate the dustbin's lid based on object proximity. The project aims to teach sensor integration, motor control, and Arduino programming through a practical application in robotics.

Uploaded by

c2x8zb2d52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Smart Dustbin using Arduino

This document outlines a project to create a Smart Dustbin using an Arduino Uno, an ultrasonic sensor, and a servo motor. It covers the materials needed, circuit connections, and provides detailed code for programming the Arduino to automate the dustbin's lid based on object proximity. The project aims to teach sensor integration, motor control, and Arduino programming through a practical application in robotics.

Uploaded by

c2x8zb2d52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

STEM- ROBOTICS

Project 3. Smart Dustbin using Arduino

Overview

In this lesson, we will build a Smart Dustbin using an Arduino Uno microcontroller, an ultrasonic
sensor for detecting objects, and a servo motor to automate the opening and closing of the dustbin
flap. This project will introduce you to basic electronics, sensor integration, and microcontroller
programming using the Arduino IDE.

Stem connection

By completing this project you will learn about:

​ •​ Sensor integration (ultrasonic sensor)


​ •​ Motor control (servo motor)
​ •​ Writing and understanding Arduino code
​ •​ Creating real-world applications of robotics, such as a contactless smart dustbin.

Materials Required

​ 1.​ Arduino Uno


​ 2.​ HC-SR04 Ultrasonic Sensor
​ 3.​ Micro Servo Motor (SG90)
​ 4.​ 9V Battery
​ 5.​ Jumper Wires
Software Required

Arduino IDE: This is the development environment where we will write and upload the code to the
Arduino board.

Components Overview

1.Arduino Uno:

A microcontroller board based on the ATmega328P. It has 14 digital I/O pins, 6 analog inputs, a
USB connection, a power jack, and more. It’s user-friendly and widely used for DIY electronics
projects.

2.HC-SR04 Ultrasonic Sensor:

Measures the distance to objects using SONAR technology. It sends out sound waves and waits
for the echo to return. Based on the time it takes for the echo to return, the distance is calculated.
​ •​ Pins:
​ •​ VCC: Power Supply (5V)
​ •​ Trig: Sends out the ultrasonic signal
​ •​ Echo: Receives the signal when it bounces back
​ •​ GND: Ground
3.SG90 Micro Servo Motor:

A small motor used for precise movements. In this project, it will open and close the dustbin lid. It’s
lightweight, affordable, and perfect for small-scale robotics.

Working Concept

The Smart Dustbin automates the opening and closing of the dustbin lid based on proximity
detection:

•HC-SR04 measures the distance to an approaching object (like your hand).


•Arduino Uno processes the signal from the ultrasonic sensor.
•Servo Motor opens the dustbin flap when an object is detected within a certain range (e.g., 50
cm).
•The flap remains open for 3 seconds and then automatically closes.

Circuit Diagram
Connections:

1.Ultrasonic Sensor:
​ VCC → 5V (Arduino)
​ GND → GND (Arduino)
​ Trig → Pin 5 (Arduino)
​ Echo → Pin 6 (Arduino)
2.Servo Motor:
​ Signal → Pin 7 (Arduino)
​ VCC → 3.3V (Arduino)
​ GND → GND (Arduino)
3.Arduino Power:
​ Connect a 9V battery to the Vin and GND pins on the Arduino to power it.

Program Code & Explanation

#include <Servo.h> // Import the Servo library

Servo servo; // Create a servo object to control the motor

int trigPin = 5; // Pin for the Trig of ultrasonic sensor


int echoPin = 6; // Pin for the Echo of ultrasonic sensor
int servoPin = 7; // Pin to control the servo motor
int led = 10; // Optional: Pin for LED

long duration, dist, average; // Variables to store duration and distance


long aver[3]; // Array to store multiple distance values for accuracy

void setup() {
Serial.begin(9600); // Begin serial communication for debugging
servo.attach(servoPin); // Attach the servo to the specified pin
pinMode(trigPin, OUTPUT); // Set the Trig pin as an output
pinMode(echoPin, INPUT); // Set the Echo pin as an input
servo.write(0); // Ensure the dustbin flap is initially closed
delay(100);
servo.detach(); // Detach servo to save power when not in use
}

void measure() {
digitalWrite(10, HIGH); // Optional: Turn on an LED when measuring distance
digitalWrite(trigPin, LOW); // Set the Trig pin low for a brief moment
delayMicroseconds(5);
digitalWrite(trigPin, HIGH); // Set the Trig pin high to send an ultrasonic pulse
delayMicroseconds(15);
digitalWrite(trigPin, LOW); // Set the Trig pin low again

duration = pulseIn(echoPin, HIGH); // Measure how long it takes for the echo to return
dist = (duration / 2) / 29.1; // Calculate the distance in cm
}

void loop() {
for (int i = 0; i <= 2; i++) { // Measure the distance multiple times for accuracy
measure(); // Call the measure function
aver[i] = dist; // Store each measurement in the array
delay(10); // Wait a short time between measurements
}

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

if (dist < 50) { // If an object is closer than 50 cm, open the dustbin
servo.attach(servoPin); // Attach the servo to control it
delay(1);
servo.write(0); // Open the dustbin flap
delay(3000); // Keep it open for 3 seconds
servo.write(150); // Close the dustbin flap
delay(1000);
servo.detach(); // Detach the servo to save power
}

Serial.print(dist); // Print the distance to the serial monitor (for debugging)


}

Code Explanation

1.Library Import and Servo Object:

We first include the Servo.h library, which allows us to control the servo motor. Then, we create a
servo object called servo.

2.Pin Configuration:

Pins are declared for the Trig and Echo pins of the ultrasonic sensor, the Servo motor, and an
optional LED.
3.Setup Function:

Serial.begin(9600) initializes serial communication, which we can use for debugging. The servo
motor is attached to the specified pin. We also configure the Trig and Echo pins as output and
input, respectively.

4.Measure Function:

This function sends out an ultrasonic pulse using the Trig pin and measures how long it takes for
the pulse to bounce back. The time is converted into a distance value in centimeters using the
formula: dist = (duration / 2) / 29.1.

5.Loop Function:

The loop function continuously monitors the distance measured by the ultrasonic sensor. If the
distance is less than 50 cm (indicating an object in front of the dustbin), the servo motor opens the
lid for 3 seconds and then closes it.

6.Average Calculation:

​ •​ The distance is measured three times to improve accuracy, and the average is taken
to reduce noise in the measurements.

7.Servo Control:

The servo.attach() function is used to engage the servo motor when needed, and servo.detach() is
used to disengage it to save power.

Customizing the Project

​ •​ Change Opening Time: You can modify the time the dustbin lid stays open by
adjusting the delay(3000) in the code. Change the value 3000 to a different number (in
milliseconds).
​ •​ Adjust Detection Range: If you want the dustbin to open at a different distance,
change the if (dist < 50) condition. Adjust 50 to the desired range in centimeters.
Conclusion

************

You might also like