HOME MADE SMART DUST BIN
CIRCUIT DIAGRAM :-
COMPONENTS REQUIRED:-
- ARDUINO UNO/NANO.
- SERVO.
- ULTRASONIC SENSOR.
- BATTERY.
- JUMPER WIRES.
SOURCE CODE :-
Servo servo1;
int trigPin = A3;
int echoPin = A4;
long distance;
long duration;
void setup()
{
servo1.attach(3); //SERVO
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
ultra();
servo1.write(80);
if(distance <= 10){
servo1.write(180);
delay(5000);
}
}
void ultra(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
}
0 Comments
Please do not Enter any Spam Link in the Comment Box
Emoji