Automatic Bridge lights

TLMXB008

Jugaadu noticed lights are still ON while there are no vehicles on the bridge. So he decided to make an automatic bridge lighting system where lights glow only when there is a vehicle on the bridge. Can you help Jugaadu in it?
Architect and Digital Kit
  1. Make a Bridge using the Architecture kit.
  2. Place US sensors on the bridge.
  3. Connect US modules with Arduino, Switch, battery and LEDs using connecting wires on bread-board.
  4. Program the Arduino and upload the sketch Using A to B USB Cable.
  5. Test it by power it on.

    

int trigPin=4;

int echoPin=5;

int led=13;

int led1=12;

void setup(){ 

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(led, OUTPUT);

pinMode(led1, OUTPUT);

}

void loop(){ 

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 20){

digitalWrite(led,HIGH);

digitalWrite(led1,HIGH);

}

else{

digitalWrite(led,LOW);

digitalWrite(led1,LOW);

}

Serial.print(distance);

delay(500);

}