Obstacle Avoider Robot Using Arduino and IR Sensor

Obstacle Avoider Robot Using Arduino and IR Sensor

Summary

Check out this blog post about building an Arduino and infrared sensor-based obstacle-avoidance robot! We guide you through every stage of the process, from building the bot and setting up the necessary parts to adding infrared sensors to identify obstacles.

Check out this amazing demo video to see how effortlessly the robot navigates around different obstacles. Plus, we've shared the complete code so you can easily get started!

Want to go deeper into the realm of robotics? Watch your robot effortlessly glide past obstacles! Don't pass up this fantastic chance in robotics!

Introduction

Obstacle avoider robots driven by Arduino and IR sensors are an excellent starting point for people interested in learning robotics.

Unlike other robotic systems, these advanced devices can explore their surroundings automatically thanks to best-in-class infrared detecting technology.

As a result, they have an incredible capacity to detect items in front of them before deciding which way is best for avoiding barriers or any prospective impediments within range.

This amazing feature makes it easier than ever before for users with little knowledge of how robots work—and who want something fun yet easy to use—to set up obstacle avoidance navigation tasks quickly and reliably without much fuss!

With such powerful sensor technology integrated into these incredible devices, your possibilities with autonomous robotics become endless!

In this blog, we will learn to build an obstacle-avoiding robot based on Infra-Red sensors.

The primary purpose of this bot is to traverse forward autonomously and change directions if it encounters any significant obstacle in its path.

The bot will avoid any obstacle big enough to be detected by the Infra-Red sensor mounted on the front.

 

read more: How to use Buzzer with Arduino

Components required to make obstacle-avoiding robot

  1. Arduino Uno (with cable)
  2. L298 Motor Driver 
  3. Range adjustable IR sensor (x3)
  4. Chassis (x1)
  5. B.O. DC Motors (x2)
  6. Battery container (x1)
  7. Wheels (x2)
  8. Castor wheel
  9. Jumper wires: male-to-male |male-to-female |female-to-female (x10)
  10. Switch (x1)
  11. Spacers (x4)
  12. M3*30 screw (x4)
  13. M3*8 screw (x15)
  14. M3 nut (x15)

read more :  Arduino Sensor types and Applications

Also, read our blog on the Infrared Sensor detailing the working principle, applications, and different types of infrared sensors.

Steps to Make Obstacle Avoider Robot Using Arduino and IR Sensor:

Step 1: Make the Robot itself

The first step is to construct the bot itself, which consists of two powered wheels and a caster wheel at the back.

The two front wheels are powered by 5V-12V B.O. motors. The caster wheel is mounted to the bot's rear.

This caster wheel ensures the overall stability of the bot while enabling unrestricted movement for the rear.

Step 2: Add the hardware required to power robot

After configuring the sensors, we must establish the robot's motion and steering system. This requires the installation of the parts that will power and turn the bot's wheels.

When everything is ready, our robot will be able to move around and investigate its environment! Now that we have everything set up, let's see how the bot moves!

We will be using an L298 motor driver to drive the wheels and the entire system will be powered by a 3S (11.1V) LiPo battery.

This twin bidirectional motor driver is based on the extremely popular L298 twin H-Bridge Motor Driver IC.

This module allows you to simply and independently operate both motors in both directions. In addition, a switch is utilized to enable and disable the bot.

 

Step 3: Add IR Sensor to detect obstacles

Now let's discuss the bot's ability to avoid obstacles. To do this, we are use three IR sensors to find any possible obstructions in the way of the robot.

The motors are controlled by an Arduino Uno R3, which uses the sensor data to help the bot avoid obstacles.

The code is rather basic and can be divided into three components.

1. Declaration of all the variables and functions that we will be using in the program.

2. Setup function: In this, we declare pins 6, 9, 10, and 11 as output pins, these pins have PWM functionality which means we can control the speed of the bot.

These pins connect to the input pins of the L298 motor driver. Two more GPIO pins have been set to high to provide 5V to the front-mounted IR sensors.

3. In the loop function, we keep reading the analog sensor values from the IR sensors and raising a flag if the bot detects an obstruction.

The potentiometer can be used to tune the sensor to detect an obstacle at a certain distance.

Once an obstacle is detected by the IR sensors, a flag is raised and the program enters a certain loop, in this loop, the bot decides to turn left or right depending on which side the obstacle has been detected.

If the left IR sensor detects an obstruction, the bot will temporarily go backward before turning right.

If the right IR sensor detects an impediment, the bot will temporarily go backward before turning left.

The bot moves back briefly and turns away from the obstacle and starts moving forward again. By default, the bot keeps moving forward until an obstacle is detected.

read our blog explaining the infrared sensor application, which provides detailed information about infrared sensor, including their working principles, types, advantages, disadvantages, and various applications.

 

Code for the obstacle avoidance Robot

#include 

//Declare all the variables being used here:
int centerIR;
int leftIR;
int rightIR;

int leftFlag;
int centerFlag;
int rightFlag;

//Declare all the functions being used here:
void deviateRight();
void deviateLeft();
void forward();
void reverse();
void setup()
{
  // put your setup code here, to run once:
 pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

 digitalWrite(7, HIGH);
 digitalWrite(8, HIGH);

  Serial.begin(115200);
}

void loop()
{
  // put your main code here, to run repeatedly:
  centerIR = analogRead(A0);
  leftIR = analogRead(A1);
  rightIR = analogRead(A2);

  if (leftIR < 200)
  {
    leftFlag = 1;
  }
  else
  {
    leftFlag = 0;
  }

 if (rightIR < 200)
  {
    rightFlag = 1;
  }
   else
  {
    rightFlag = 0;
  }

  if (centerIR < 200)
  {
    centerFlag = 1;
  }
  else
  {
    centerFlag = 0;
  }

  if ((leftFlag == 1) || (rightFlag == 1) || (centerFlag == 1))
  {

    if (centerFlag == 1)
    {
      if (leftFlag == 1)
      {
        deviateRight();
      }

      elseif (rightFlag == 1)
        deviateLeft();
      else
        deviateLeft();
    }
    elseif (leftFlag == 1)
    {
      deviateRight();
    }
    elseif (rightFlag == 1)
    {
      deviateLeft();
    }
    else
    {
      deviateLeft();
    }
  }

 else
  {
    forward();
  }
}

//Function definitions go here:
void reverse()
{
  Serial.println("Backing up");
  digitalWrite(9, LOW);
  analogWrite(6, 75);
  analogWrite(11, 75);
  digitalWrite(10, LOW);
  delay(1000);
}

void deviateRight()
{
  Serial.println("Right");
  reverse();
  digitalWrite(6, LOW);
  digitalWrite(9, LOW);
  digitalWrite(11, LOW);
  analogWrite(10, 350);
  delay(300);
}

void deviateLeft()
{
  Serial.println("Left");
  reverse();
  analogWrite(9, 350);
  digitalWrite(6, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  delay(300);
}

void forward()
{
  Serial.println("Forward");
  analogWrite(9, 75);
  digitalWrite(6, LOW);
  digitalWrite(11, LOW);
  analogWrite(10, 75);
}

Once the code has been uploaded on the Arduino Uno, power on the bot.

Before placing it on the ground, please ensure that the bot is behaving in the way it is intended to, you can do this by waving your hand in front of the IR sensors in the front.

This will ensure that the bot does not get damaged by any obstacles. 

read more: Smart Dustbin using Arduino

Conclusion:

Creating an Obstacle Avoidance Robot with Arduino and infrared sensors is an exciting project that blends technology and imagination.

Follow our guide to assemble your robot, set up the necessary parts, and use an IR sensor to help your bot navigate around obstacles. This arrangement allows your robot to traverse its surroundings automatically.

Do not miss the demo video to show your robot in action as it explores its surroundings. If you're ready to get started with programming, our obstacle avoidance code has you covered.

Start today and feel the thrill of robotics for yourself!

 

If you appreciate our work don't forget to share this post and leave your opinion in the comment box.

 

Please do check out other blog posts about Popular electronics

 

Make sure you check out our wide range of products and collections (we offer some exciting deals!) 

Components and Supplies

You may also like to read

Frequently Asked Questions

1. What is the IR sensor used for obstacle detection?

The IR sensor is a device that provides obstacle detection for robots, drones and other automated machines. It utilizes infrared radiation to detect obstacles in its path and alert the machine accordingly so it can avoid them. With this knowledge, these devices or vehicles are able to circumnavigate around objects as needed.
Objects which emit heat create an energy signature on electromagnetic spectrums including the near-infrared spectrum; when exposed to such frequencies of light―which our eyes cannot see due to their wavelength ―the sensors detect changes between what’s expected from open space with no barriers versus areas where blockages exist . The result allows machinery precision navigation capabilities without risk of collision damage or disruption of progress. This makes tasks much less time-consuming than traditional methods like manual labor while also allowing greater safety assurance since human error is eliminated altogether by relying solely on technology rather than people delivering results across high-scale projects requiring accurate measurements over long distances quickly & precisely. 

read more : What is the microcontroller used in Arduino UNO?

2. How do you make an obstacle avoiding robot with IR sensor?

Making an obstacle-avoiding robot with an IR sensor is a fun and easy project. It involves programming to make your robot detect obstacles in its path, avoid them and move forward. Start by getting the necessary materials, including batteries for power supply, motor drivers to control the movement of motors connected directly to wheels or tracks of the robot, Arduino board along with other electronic components like Raspberry Pi4 etc., depending if AI based department is considered with several cables connecting parts together as per circuit diagram. Once all material has been gathered it is time for coding which requires some level of understanding of C/C++ language (or whichever one you prefer). The code should include functions that allow proper operation such as sending signals after interruptions from infrared sensors alerting about nearby objects while moving across space & accordingly commands must be deployed through wires so that needed motion changes can occur immediately without any harm caused due too sudden speed adjustments thus achieving desired purpose i.e safe navigation among fixed or mobile environment via integration between hardware & software technology!

read more : Top 10 Arduino Projects to Get Started With

3. How does an IR obstacle avoidance sensor work?

The IR (infrared) obstacle avoidance sensor is a handy device that uses infrared light to recognize obstacles in its path. It works by producing an infrared light beam using an LED that reflects off of obstacles. The sensor's receiver then detects the reflected light and signals the existence of an obstruction by delivering a low-level signal to the OUT pin. The LED on the sensor illuminates to provide a visual signal. The sensor's sensitivity and detection range may be adjusted from 2 to 30 cm using a potentiometer. Reflective materials, such as white, work best for the sensor since they return more infrared light, making detection simpler. 

4. What is the aim of obstacle avoiding robots?

Robots that can avoid obstacles are designed to navigate their environment safely and without hitting objects. The robot can recognize obstacles and choose the best path around them thanks to sensors. The robot might be able to move more quickly with this skill without endangering the surroundings or itself. As a result of its ability to function in a range of environments, including chaotic and dynamic ones, the robot is more adaptable and useful. Robots that are effective and useful in daily life must be able to avoid obstacles.

5. What is an obstacle avoiding robot?

An obstacle-avoiding robot is a type of mobile robot that can smoothly navigate its surroundings by sensing and steering clear of objects in its way. It uses sensors, like ultrasonic sensors, to detect obstacles and then makes adjustments to its path so it can move without stopping suddenly in front of them. This ability helps the robot travel smoothly in new or unpredictable environments while avoiding collisions. Obstacle avoidance is essential for robots to move freely and confidently, making them more useful in a wide range of real-world situations.

6. Where is the obstacle avoiding robot used?

Obstacle-avoiding robots have a range of uses that make our lives easier and safer. They prevent other mobile robots from hitting barriers and objects, allowing them to navigate more easily. When utilizing a mechanical vacuum to clean the floors at home, they can go around furniture and other obstructions with ease. These robots assist us in performing critical activities while keeping people out of hazardous locations, such as poisonous or disaster-prone areas, where people are at risk.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.

Components and Supplies

You may also like to read