Sunday 24 August 2014

Obstacle avoiding robot using IR module


                Every embedded enthusiast would have certainly done this project when he/she started to think about moving robot vehicles….! This is my first robot too…….

The main part of this project is the sensor that senses the objects in front of it. For this purpose there are two popular sensors available in the market. One is the Ultrasonic sensor and the other is the Infrared (IR) sensor. Here we are going to learn about IR sensor.

                All you should do for the project is to have these parts,

1.       IR module

2.       GR – Sakura (or any Arduino Compatible Boards)

3.       Two DC motors with wheels

4.       An omni-directional wheel

5.       L293D Motor Driver

6.       Chassis

IR module:

                Here is the IR module that I bought it from a local electronic shop (Rs.125).

 
Working of an IR module is given below
In the module that I use, the digital output would be 1 if there is no object in front of it and when there is an obstacle, the module gives logic 0 as output. Read your module datasheet for more details.

Chassis and wheel setup:

 
L239D Motor Driver:
                For tutorial on L293D motor interface, visit this post – Motor interface with L293D
I have made my own L293D motor driver board. Here is the picture,

Robot Full Setup:

 

From the picture you can see that I have used two 9V batteries to power up. A single 9V battery is enough to power up the robot, if the battery is a new one.

Note: These 9V batteries may drain out quickly and hence the motors won’t function properly. This is a common issue, and many of them would think that it was either a software / hardware problem.


On the other hand, if you connect two batteries in parallel, then their current capacity would get added up. That’s why I have added two battery packs to increase the current capacity.



Code:


// Motor 1 – connected left side

// Motor 2 – connected right side

#include<rxduino.h>
void obstacle();

main()

{
                pinMode(30,INPUT);             // IR module data

                pinMode(7,OUTPUT);                   
                pinMode(6,OUTPUT);

                pinMode(5,OUTPUT);

                pinMode(4,OUTPUT);
                pinMode(PIN_LED0,OUTPUT);

                digitalWrite(7,0);
                digitalWrite(6,0);

                digitalWrite(5,0);
                digitalWrite(4,0);

                while(1)
                {
                                if(digitalRead(30)==0)        // if IR module data is 0 (obstacle detected)

                                {
                                                obstacle();
                                }

                                digitalWrite(PIN_LED0,1);

                                digitalWrite(7,1);           // motor 1 forward
                                digitalWrite(5,1);          // motor 2 forward
                }
}

void obstacle()
{
                digitalWrite(PIN_LED0,0);

                digitalWrite(7,0);

                digitalWrite(5,0);
                delay(10);

                digitalWrite(6,1);                // motor 1 reverse
                digitalWrite(4,1);                // motor 2 reverse

                delay(700);
                digitalWrite(6,0);

                digitalWrite(4,0);
                int randomno=random(10);            //random number generator from 0 to 9

                if((randomno%2)==0)                     // if even number turn right
                {
                                digitalWrite(7,1);            //  turn right side

                                delay(1100);                   // turning time - can be varied according to your needs
                                digitalWrite(7,0);          
                }

                if((randomno%2)==1)              // if even number turn left
                {
                               digitalWrite(5,1);           //  turn left side

                                delay(1100);                   // turning time - can be varied according to your needs
                                digitalWrite(5,0);

                }
}

I have a used a random number generator to make it turn either left or right when an obstacle is detected. You can even use any other concepts to make it happen.........

Video demo:

 

1 comment:

  1. Dude can you show the connections??????
    I mean its not clear in the picture that you uploaded....

    ReplyDelete