Arduino projectsDIY Robots

Obstacle Avoiding Bot

Obstacle Avoiding Bot is one the most famous autonomous, interesting and simple bot to make with Arduino .

We will be making a simple obstacle avoiding bot that uses Ultrasonic Sensor to detect any obstacle in its path and turn accordingly to avoid it(Note: you can use IR sensor instead of Ultrasonic with little changes in code).

Here, once the obstacle is detected in the near vicinity of bot then its take Left turn (or right turn) and move forward again in the same fashion.

It’s a simple Obstacle Avoiding Bot so, its path planning is limited but you can further add Ultrasonic with  Servo so that it can sweep the front path of the  bot to move in the most cleared path, we will see that in other project.

With just changing the position of Ultrasonic sensor you can make it a Smart EDGE AVOIDER Robot.

Working Principle:

Components Required:

  • Arduino Uno/Nano/Mega (Amazon/Ebay/Flipkart/AliExpress)
  • Ultrasonic Sensor (Amazon/Ebay/Flipkart/AliExpress)
  • Jumper Wires (Amazon/Ebay/Flipkart/AliExpress)
  • Motor Driver (Amazon/Ebay/Flipkart/AliExpress)
  • BO Motors    (Amazon/Ebay/Flipkart/AliExpress)
  • Chassis+Wheels
  • 9V Battery

*Please note: These are affiliate links. I may make a commission if you buy the components through these links.
I would appreciate your support in this way to help this website!

Circuit / Schematics:


Code Section:

/* This code is written by Alok Shaw , you can get more such tutorials on For video tutorials visit */
const int RMF = 3;
const int RMB = 4;
const int LMF = 5;
const int LMB = 6;

const int trigPin = 9;
const int echoPin = 8;

void setup() 
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode (RMF, OUTPUT);
pinMode (RMB, OUTPUT);
pinMode (LMF, OUTPUT);
pinMode (LMB, OUTPUT);
long duration, distance;

void loop()
digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW); 
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2;
if(distance<20) // When distance of Obstacle is less than 20 cm then turn LEFT
digitalWrite(RMF, HIGH); // For the bot to make a RIGHT turn instead of LEFT turn change (HIGH to LOW) and (LOW to HIGH)
digitalWrite(RMB, LOW); 
digitalWrite(LMF, LOW); 
digitalWrite(LMB, HIGH);

else // When there is no obstacle under 20cm then the bot moves forward.
digitalWrite(RMF, HIGH); 
digitalWrite(RMB, LOW); 
digitalWrite(LMF, HIGH); 
digitalWrite(LMB, LOW);
// delay(100);





Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button