Introduction: Obstacle Avoider Using Ir Sensor

Hey guys I'm going to show you how to make a obstacle avoider using ir sensors and an arduino
This project doesn't require any costly material and is quite easy to make
So let's begin

Step 1: Parts Needed

You will need for this project :
2 IR sensors
1 arduino uno
1 breadboard
2 100 RPM dc motors
2 mosfets
1 chassis and 4 wheels (obviously)
1 9v battery and 1 12v battery
1 9V battery to Arduino jack(easily available online as well as in any electrical shop)
Led buzzer resistor (optional)
Jumper wires

Step 2: Making the Connections

For the motors connect them through the mosfet to the arduino as shown in the picture

For the IR sensors
Connect the vcc to 5v on the arduino through the breadboard and connect the data pin to the output pin of your choice on the arduino and ground to ground
If you are unclear about which pin on the sensor is what then hold the sensor facing towards you such that the pins are on your right
The bottom most pin is the vcc the middle pin is the data pin and the and the top most pin is the ground pin

Step 3: Putting It Together

Now place the breadboard, 12v battery and the arduino on the chassis
Now place the IR sensors
I place them in front of the wheels so when the robot turns the wheels are also cleared and they don't bang into the obstacle
I used some ice cream sticks and pieces of thermocol to do it
Make sure the base on which the sensors are resting is firm
Place the battery and breadboard in such a way that the distribution of weight on the chassis is equal on both the motors
I placed my battery and the back but not too much on the edge
You can place it in front also

Step 4: Additional Outputs

This step is optional
I added these only after I was convinced that the robot is avoiding obstacles smoothly
Here you can add leds and buzzer which which will go on if either of the sensor detects an object

Step 5: The Arduino Code

Int motor=6;

Int motor2=7;
Int led=10;;
Int led2=11;
Int buzz=2;
Int buzz2=3;
Int irr=9;
Int irl=12;
Int irrval;
Int irlval;

Void setup () {
pinMode(motor, OUTPUT);
pinMode (motor2, OUTPUT);
pinMode (led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode (buzz, OUTPUT)
pinMode (buzz2, OUTPUT);
pinMode irr, INPUT);
pinMode (irl , INPUT);
void loop () {
Irrval=digitalRead (irr);
Irlval = digitalRead (irl);

if (irrval> 0) {
digitalWrite (motor, LOW);
digitalWrite(led, HGH);
digitalWrite (buzz, HIGH);
delay (50);
else {
// replace low with high and high with low//
if (irlval> 0) {
digitalWrite (motor2, LOW);
digitalWrite (led2, HIGH);
digitalWrite (buzz2, HIGJ);
delay (50);
else {//replace high with low and low with high//

Step 6: Connecting 9v Battery to Arduino

Here take a jack which connects a 9V battery to the arduino(easily available in any electrical components shop or online) The jack comes with a short length of wire between the part to be connected to the arduino and the part to be connected ti the 9V battery.If u wish you can cut off the wire in between and add a switch there.

Before connecting it to arduino make sure that it is fully charged(use a Multi-Meter).This is because somtimes when the battery has less than 8V charge left the arduino doesnt work.\

Now connect the battery to arduino and impress your friends with an awesome obstacle avoiding robot!!!


Thanks for viewing this instructable.....hope you enjoyed it

Any doubts or questions please do post in the comments below