In this article, we learn about how to make smart dustbin using Arduino . now lets know about what are the components required to make this project.
components:
amazon links :
- Arduino BuyNow
- ultrasonic sensor BuyNow
- Breadboard and wires BuyNow
If you want to buy Arduino components, I am giving my affiliate links. If you buy the components using my affiliate links, it will help to our channel and website growth. so do these small help.
Making Video:
watch the below video to batter understand to make this project.
How to make a smart dustbin using Arduino circuit diagram
connect the all the components as shown in above circuit.
How to make a smart dustbin using Arduino code:
#include <Servo.h>
Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 3;
long duration, dist, average;
long aver[3];
void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0);
delay(100);
servo.detach();
}
void measure() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1;
}
void loop() {
for (int i=0;i<=2;i++) {
measure();
aver[i]=dist;
delay(10);
}
dist=(aver[0]+aver[1]+aver[2])/3;
if ( dist<50 ) {
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}
If you have any doubts regarding to this project, contact me on Instagram or comment on YouTube video. I will help with my best.
look this article also obstacle avoiding robot using arduino
0 Comments