Front and Rear Collision Alert Bot

TLMXB004

While going to school Jugaadu saw an accident. Someone hit a boy at the time of taking the car backward. He didn't see the boy behind his car from mirrors. So Jugaadu decided something to alert drivers for such circumstances. Can you help Jugaadu to do so?
Robotics and IoT kit
  1. Place two US sensors, one at the Backside of Car and the Second one in front of the car.
  2. Connect US modules with Arduino, switch, battery and Buzzers using connecting wires on bread-board.
  3. Program the Arduino and upload the sketch Using A to B USB Cable.
  4. Test it by power it on.

    

int out1=8;

int out2=9;

int in1=2;

int in2=3;

int in3=4;

int in4=5;

int buz=11;

int dir = 0;

int en1=6;

int en2=7;

void setup() {

// put your setup code here, to run once:

pinMode(out1,INPUT);

pinMode(out2,INPUT);

Serial.begin(9600);

pinMode(in1,OUTPUT);

pinMode(in2,OUTPUT);

pinMode(in3,OUTPUT);

pinMode(in4,OUTPUT);

pinMode(buz,OUTPUT);

pinMode(en1,OUTPUT);

pinMode(en2,OUTPUT);

}

void loop() {

// put your main code here, to run repeatedly:

if(digitalRead(out1)==0)

dir = 1;

else if (digitalRead(out2)==0)

dir = 0;

if(dir == 1){

digitalWrite(in1,LOW);

digitalWrite(in2,LOW);

digitalWrite(in3,LOW);

digitalWrite(in4,HIGH);

digitalWrite(buz,LOW);

}

else if(dir == 0){

digitalWrite(in1,HIGH);

digitalWrite(in2,LOW);

digitalWrite(in3,LOW);

digitalWrite(in4,LOW);

digitalWrite(buz,HIGH);

}

}