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 comment
  • 12 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.


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 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
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {

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
  else if(sR<600 && sL>600)//If the right sensor is near an obstacle
  {;//First move back for 1 second;
      delay(1000);;//Then turn left for 1.5 seconds;
  else if(sR>600 && sL<600)//If the left sensor is near an obstacle
  {;//First move back for 1 second;
      delay(1000);;//Then turn right for 1.5 seconds;
  else if(sM<600)//If the middle sensor is near an obstacle
  {;//First move back for 2 seconds;
      delay(2000);;//Then turn right(arbitrary,you could go left too);//For 1.5 seconds
  else//If its none of the above,just move backwards for 2 seconds


Connection of the 3 IR sensors with Arduino


Similar projects you might like

Bluetooth Controlled Bot (Using Adafruit L293D Motor Driver)

Project showcase by Chandran N

  • 1 comment
  • 15 respects

Robotic Car controlledover Bluetooth with Obstacle Avoidance

Project showcase by S.Ranjith Reddy

  • 25 respects

Big Track Rover "ENHANCED EDITION" Obstacle Avoidance Bot

Project showcase by Sam

  • 1 comment
  • 3 respects

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project showcase by Jorge Rancé

  • 50 respects

Graphical Programming Obstacle Avoidance Robot

Project tutorial by Team KittenBot

  • 1 comment
  • 17 respects

Home Safety Bot

Project showcase by Team HomeSafety

  • 18 respects
Add projectSign up / Login