Obstacle Avoiding Bot

Did you ever thought of a Car or a Robot that can Avoid Obstacles ???
Yeah!!!!!!
This is Nivesh Niwas and I am back with my new Robot which is an OBSTACLE AVOIDER.

So without wasting any time let’s start.

Firstly we are going to decide the parts which we gonna use…//

The Parts Are

1. Arduino
2. Ultrasonic sensor : An Ultrasonic sensor can measure the distance to an object by using sound waves.
3. BreadBoard
4. 2xGeared Motors
5. An L293D IC or H-Bridge
6. Chassis
7. 2xtires
8. Some Jumper wires
9. Battries
Connect them together as shown in the following schematic diagram.

Now wiring part is done.
Now upload the code to the Arduino.
Code :

const int trig = 9;
const int echo = 8;
const int leftForward = 5;
const int leftBackward = 4;
const int rightForward = 6;
const int rightBackward = 7;

int duration = 0;
int distance = 0;

void setup()
{
pinMode(trig , OUTPUT);
pinMode(echo , INPUT);
pinMode(leftForward , OUTPUT);
pinMode(leftBackward , OUTPUT);
pinMode(rightForward , OUTPUT);
pinMode(rightBackward , OUTPUT);

Serial.begin(9600);

}

void loop()
{
digitalWrite(trig , HIGH);
delayMicroseconds(1000);
digitalWrite(trig , LOW);

duration = pulseIn(echo , HIGH);
distance = (duration/2) / 28.5 ;
Serial.println(distance);

if ( distance < 20 )
{
digitalWrite(leftForward , LOW);
digitalWrite(leftBackward , HIGH);
digitalWrite(rightForward , HIGH);
digitalWrite(rightBackward , LOW);
delay(100);
}
else
{
digitalWrite(leftForward , HIGH);
digitalWrite(leftBackward , LOW);
digitalWrite(rightForward , HIGH);
digitalWrite(rightBackward , LOW);
}

}

Have a look at the video

THANK YOU