#include <Servo.h>
Servo servo;
const int trigP = 13;
const int echoP = 5;
long duration;
int distance;
void setup() {
pinMode(2, OUTPUT);
pinMode(trigP, OUTPUT);
pinMode(echoP, INPUT);
pinMode(9, OUTPUT);
pinMode(6, INPUT);
servo.attach(9);
Serial.begin(9600);
}
void loop() {
int x = digitalRead(6);
digitalWrite(trigP, LOW);
delayMicroseconds(2);
digitalWrite(trigP, HIGH);
delayMicroseconds(10);
digitalWrite(trigP, LOW);
duration = pulseIn(echoP, HIGH);
distance = duration*0.034/2;
servo.write(0);
//int y =map(x,2,400,0,180);
if (distance<25){
// Serial.println(" Dustbin Full");
digitalWrite(2, HIGH);
delay(1000);
}
else{
if(x==HIGH)
{
servo.write(90);
delay(x);
}
else{
servo.write(0);
}
digitalWrite(2, LOW);
delay(1000);
}
}