Obstacle Avoiding Robot using IR Sensor

posted in: DIY - Engineering | 0

This is the cheapest obstacle avoiding bot using a single IR module and Arduino Uno…

Components:
1) Arduino Uno
2) L293D motor driver board
3) Chasis with two wheels powered by two dc motors and one castor wheel in the front.
4) Connecting Wires.
5) IR module
6) Power source for Arduino Uno and the motors.

This project can be done either by using a motor driver board or a customized driver board which can be made using L293D chip.

The circuit diagram image is uploaded for both customized board and motor driver board.

With motor driver,
The image shown below has connections for motor driver and the IR module separately with the Arduino uno.

motor driver and ir module connections

 

 

 

 

 

The image shown below has complete circuit of the project,

Complete circuit using motor driver

With the L293D customized board,

The image shown below has the L293D connections with the arduino pins. IR module connections remain the same. Use a bread board for the connections when prototyping.
L293D circuit
Program for Arduino:
/* Defining the pins for motors*/
 int motA1=4;
 int motA2=5;
 int motB1=6;
 int motB2=7;
 int senAread=9; /*Defining the sensor pin*/
/* Setting up the Arduino pins as either INPUT or OUTPUT pins*/
 void setup()
 {
/*Defining the pins as either INPUT or OUTPUT mode*/
  pinMode(motA1,OUTPUT);
  pinMode(motA2,OUTPUT);
  pinMode(motB1,OUTPUT);
  pinMode(motB2,OUTPUT);
  pinMode(senAread, INPUT);
/* Setting up the initial conditions of the pins*/
  digitalWrite(motA1,HIGH);
  digitalWrite(motA2,LOW);
  digitalWrite(motB1,HIGH);
  digitalWrite(motB2,LOW);
 }
 void loop()
 {
  int val1=digitalRead(senAread);
        if(val1 == HIGH)
    {
     digitalWrite(motA2,HIGH);
     digitalWrite(motA1,LOW);
     digitalWrite(motB2,HIGH);
     digitalWrite(motB1,LOW);
     delay(1000);
     digitalWrite(motA1, LOW);
     digitalWrite(motA2, HIGH);
     digitalWrite(motB1, HIGH);
     digitalWrite(motB2, LOW);
     delay(700);
     digitalWrite(motA1, HIGH);
     digitalWrite(motA2, LOW);
     digitalWrite(motB1, HIGH);
     digitalWrite(motB2, LOW);
    }
  else
  {
    digitalWrite(motA1,HIGH);
    digitalWrite(motA2,LOW);
    digitalWrite(motB1,HIGH);
    digitalWrite(motB2,LOW);
  }
 }
/* Looping such that when sensor value is HIGH, the bot changes it’s direction*/
The distance for which the IR sensor must be high can be calibrated in the IR module itself. Every IR module has a calibrating knob.
If u want to adjust the distance in program, replace the void loop() with the below code,
 void loop()
 {
  int val1=digitalRead(senAread);
        if(val1 <= 2) /* Here i adjusted the code to act for 2cm */
    {
     digitalWrite(motA2,HIGH);
     digitalWrite(motA1,LOW);
     digitalWrite(motB2,HIGH);
     digitalWrite(motB1,LOW);
     delay(1000);
     digitalWrite(motA1, LOW);
     digitalWrite(motA2, HIGH);
     digitalWrite(motB1, HIGH);
     digitalWrite(motB2, LOW);
     delay(700);
     digitalWrite(motA1, HIGH);
     digitalWrite(motA2, LOW);
     digitalWrite(motB1, HIGH);
     digitalWrite(motB2, LOW);
    }
  else
  {
    digitalWrite(motA1,HIGH);
    digitalWrite(motA2,LOW);
    digitalWrite(motB1,HIGH);
    digitalWrite(motB2,LOW);
  }
Upload the program to arduino and connect the circuit connections.
The pic of the bot which I made,
OAR
Thanks for reading my post…..
Comments are closed.