my project involves: 1 ultrasonic sensor. 1 servo motor. 3 leds. when a person comes in range of ultrasonic sensor (7 to 20),servo turns by 150 degree. then ultrasonic sensor check again if the person is in range, if yes then led1 turns on for 10sec n turns off, still if the person in in range then led2 turns on for 10sec and turns off, still if the person is in range then led3 turns on for 10sec and this keep on repeating for the leds(led1, led2, led3 but servo is still in 150) once detected and the person is not detected the leds should not glow and servo should return to 0
code:
if ((distance1>7)&&(distance1 <= 20))
{
myservo1.write(150);
delay(1000);
}
{
if ((distance2>7)&&(distance2 <= 20))
{
digitalWrite(led1,HIGH);
delay(1000);
digitalWrite(led1,LOW);
}
if ((distance1>7)&&(distance1 <= 20))
{
digitalWrite(led2,HIGH);
delay(1000);
digitalWrite(led2,LOW);
}
if ((distance1>7)&&(distance1 <= 20))
{
digitalWrite(led3,HIGH);
delay(1000);
digitalWrite(led3,LOW);
}
else
{
myservo1.write(0);
}
but this code does not work the way i want. it blink the leds even when there is no person in range. need help in programing so that the leds blink only when ultrasonic detects the person in range and stops when person is not detected. thank u in advance