Project tutorial
Obstacle Avoidance Bot Using IR Sensors

Obstacle Avoidance Bot Using IR Sensors © GPL3+

When my ultrasound sensor stopped working, I decided to improvise by making an obstacle avoidance bot using IR sensors (cheaper too).

  • 1,246 views
  • 0 comments
  • 7 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

So a few days ago, My ultrasound sensor stopped working and started giving 0s as output when I tried to use it.I did a lot of research to try and fix it(reducing voltage,new ping library etc) but to no avail(If any of you have an idea on how to resolve this,please put it in the comments below).

Undeterred,I decided to make an Obstacle Avoidance Bot using Infrared Proximity Sensors.They happen to be cheaper too(not by a large margin though) and I did have a few of them from my line follower bot.

The objective is simple-if the sensors encounter an obstacle they move back and turn left or right as the case may be.

So I will call the three sensors sL,sM and sR for left,middle and right respectively.

The connections are rather straight forward-

All the 3 IR sensors receive 3.3V from Arduino(I did not risk 5V although I am told there will be no problem) and are connected to the same GND pin.

sR is connected to A0

sL is connected to A2

sM is connected to A5

The right motor is connected to M1 of the motor shield and the left motor to M2.

Once this is all completed,the bot is good to go.

IMPORTANT-

The Infrared sensor as shown above has proved to be efficient in its task.However there is one extremely important point which I must address.Infrared proximity sensors are greatly affected by external light.In my code,the bot avoids obstacle if the sensor value is below 600.This value however changes based on external lighting in the place where you work and try the bot.I strongly recommend you to first run a Analog Read Serial code on your Arduino,determine the correct threshold and use it in your program.In fact this is one of the main disadvantages of using Infrared senors rather over Ultrasonic sensors. Please pay great care to this point.

.

Code

Code implemented for the botArduino
You can directly copy it if you are using Adafruit Motor Shield,otherwise you need to make changes in how you run the motor.(However please read the important message at the bottom of the story before uploading the code)
//The bot on encountering an obstacle first moves back and then moves in a particular direction.This is completely arbitrary,you can modify the same if you want
#include<AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {
  Serial.begin(9600);
  motor1.setSpeed(200);
  motor2.setSpeed(200);
}

void loop() {
int sR = analogRead(A0);//Right sensor
int sL = analogRead(A2);//Left sensor 
int sM = analogRead(A5);//Middle sensor
  if(sR>600 && sL>600 && sM>600)//In the event of no obstacle being detected by any of the sensors
  {   
      motor1.run(FORWARD);
      motor2.run(FORWARD);
  }
  else if(sR<600 && sL>600)//If the right sensor is near an obstacle
  {   
      motor1.run(BACKWARD);//First move back for 1 second
      motor2.run(BACKWARD);
      delay(1000);
      motor1.run(FORWARD);//Then turn left for 1.5 seconds
      motor2.run(RELEASE);
      delay(1500);
  }
  else if(sR>600 && sL<600)//If the left sensor is near an obstacle
  {   
      motor1.run(BACKWARD);//First move back for 1 second
      motor2.run(BACKWARD);
      delay(1000);
      motor2.run(FORWARD);//Then turn right for 1.5 seconds
      motor1.run(RELEASE);
      delay(1500);
  }
  else if(sM<600)//If the middle sensor is near an obstacle
  {   
      motor1.run(BACKWARD);//First move back for 2 seconds
      motor2.run(BACKWARD);
      delay(2000);
       motor2.run(FORWARD);//Then turn right(arbitrary,you could go left too)
      motor1.run(RELEASE);//For 1.5 seconds
      delay(1500);
      
  }
  else//If its none of the above,just move backwards for 2 seconds
  {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    delay(2000);
  }
  delay(100);
}

Schematics

Connection of the 3 IR sensors with Arduino
ir_connections_with_arduino_JsoWN4jZx9.fzz

Comments

Similar projects you might like

Robotic Car controlledover Bluetooth with Obstacle Avoidance

Project showcase by S.Ranjith Reddy

  • 12,117 views
  • 8 comments
  • 21 respects

Bluetooth Controlled Bot (Using Adafruit L293D Motor Driver)

Project showcase by Chandran N

  • 132 views
  • 0 comments
  • 8 respects

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project showcase by Jorge Rancé

  • 16,961 views
  • 8 comments
  • 38 respects

Graphical Programming Obstacle Avoidance Robot

Project tutorial by Team KittenBot

  • 2,652 views
  • 1 comment
  • 14 respects

Home Safety Bot

Project showcase by Team HomeSafety

  • 879 views
  • 2 comments
  • 10 respects

Simple Obstacle Sensor with Arduino

Project tutorial by muhammed shameel k.v

  • 8,160 views
  • 2 comments
  • 11 respects
Add projectSign up / Login