Chandran N
Published © GPL3+

Obstacle Avoidance Bot Using IR Sensors

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

EasyFull instructions provided2 hours1,285
Obstacle Avoidance Bot Using IR Sensors

Things used in this project

Hardware components

IR Proximity Sensor
Digilent IR Proximity Sensor
×3
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Adafruit motor shield
×1
Jumper wires (generic)
Jumper wires (generic)
×3
Breadboard (generic)
Breadboard (generic)
×1
DC motor (generic)
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Digilent Screwdriver
Digilent Screwdriver

Story

Read more

Schematics

Connection of the 3 IR sensors with Arduino

Code

Code implemented for the bot

Arduino
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);
}

Credits

Chandran N

Chandran N

3 projects • 1 follower
I am a student at NITK Surathkal pursuing Mechanical Engineering.I am interested in Robotics,Arduino,IoT,Automobiles and Astronomy.

Comments

Add projectSign up / Login