int led = 11;
int buzzer = 2;
int echo1 = 4;
int trig1 = 5;
int echo2 = 7;
int trig2 = 6;
int time;
int distance;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trig1, OUTPUT);
pinMode(echo1, INPUT);
pinMode(trig2, OUTPUT);
pinMode(echo2, INPUT);
pinMode(c, OUTPUT);
pinMode(buzzer, OUTPUT);
// put your setup code here, to run once:
}
void loop() {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
time = pulseIn(echo, HIGH);
distance = (0.034*time)/2;
Serial.print("Distance = ");
Serial.println(distance);
if (distance<=100){
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(buzzer, LOW);
delay(500);
}
else if((distance>100) and (distance<=389))
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(buzzer, LOW);
delay(500);
}
else if((distance>390))
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(buzzer, HIGH);
delay(500);
} // put your main code here, to run repeatedly:
}