long duration, distance;
const int echoPin = 7;
const int trigPin = 8;
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(13,OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/57.8; // (cm)
Serial.println(distance);
delay(50);
if (distance > 300);{
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
if (distance > 200 && distance <= 300);{
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
if(distance <= 200);{
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
}
}