In this project, I’m going to show you about smart dustbin using Arduino and ultrasonic sensor (HC SR-04). Everywhere people are On investigating on several aspects in several fields for making smart cities to enhance civilization and human efforts.
CONSTRUCTIONAL DETAILS:
- Echo pin is connected to Arduino pin 9
- Trigger pin is Connected to Arduino pin 8
- Vcc pin is connected to +5V Supply in arduino board
- GND is connected to GND pin of Arduino Uno
In the servo motor,
- Yellow wire is connected to the arduino pin 10
- Red wire is connected to the +5V Supply in arduino board
- GND wire is connected to GND pin of Arduino Uno
WORKING:
- Let’s get into the details, First of all take a piece cardboard and mate it like a box with as shown in the video or plastic bucket.
- Ultrasonic Sensor is placed outside of the plastic bucket or box which we had chosen why because when any Obstacle came across the ultrasonic Sensor (HC SR-04) then it give signals to the servomotor.
- Then the servo motor which is placed inside the box operates to open the lid of the smart dustbin.
- Dump the source code into the Arduino board, if you have any doubt check in the video
Arduino UNO:
Ultrasonic sensor:
REQUIREMENTS:
- Arduino Uno
- Ultrasonic sensor
- Servo motor
- plastic bucket or card board
- Connecting wires
CIRCUIT DIAGRAM:
VIDEO:
PROJECT CODE:
#include<Servo.h>
const int trigPin = 8;
const int echoPin = 9;
const int servoPin = 10;
// defines variables
double SetDelay, Input, Output, ServoOutput;
Servo myServo; //Initialize Servo.
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
myServo.attach(servoPin); //Attach Servo
Input = readPosition();
}
void loop() {
Input = readPosition();
ServoOutput=Input;
myServo.write(ServoOutput);
if(ServoOutput ==140)
{
SetDelay=3000;
}
else{
SetDelay=100;
}
delay(SetDelay);
}
float readPosition() {
delay(40);
long duration, var;
int distance;
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration/(29*2);
// Prints the distance on the Serial Monitor
Serial.print(“Distance: “);
Serial.println(distance);if(distance <68) {
var=140;
}
else{
var=50;
}
//Returns distance value.
return var;
}
Added by
admin
WRITE A COMMENT
WRITE A COMMENT
No comments yet