Arduino Line Follower Robot With Obstacle Detection

In previous projects, we talked about various Arduino basis Robotics projects. Now we are going to build a two-in-one robot which is an Arduino line follower robot with obstacle detection using some simple components. This is an autonomous robot that detects a black or white path and follows according to the path drawn. It follows the path with the help of an infrared sensor attached to the robot. The path can either be a black line or a white line, thus it avoids any detection errors.

This Line follower robot has an obstacle sensor (HC-SR04 Ultrasonic Sensor) that detects any type of obstacle in front of the robot so that there is no accident happening with the robot. Line follower robot is designed and programmed in such a way that it can follow the path without any errors. It operates in such a way that it detects and reads the path and transmits the signal to Arduino UNO. Then the microcontroller decides to make any changes in the directions and speed of the robot according to the inputs given by the Arduino. Thus, it sends the analog signal to the speed and directions of the line follower robot. To make a line follower robot with obstacle detection ability, it is attached with an ultrasonic sensor, which is a device that can measure the distance between an object and a robot sensor by using ultrasonic waves.

Must Read Line Follower Robot Without Microcontroller

Principle Behind Line Follower Robot

The Line Follower Obstacle Avoidance Robot consists of two infrared sensors and an HC-SR04 ultrasonic sensor attached to it. When the left IR sensor senses the black line, then the robot turns on the left side and if the right IR sensor senses the black line, then the robot turns the right side. Until both the left and right IR sensors sense the white area, the robot moves forward continuously. If the robot comes across a path where there is another black strip lying perpendicular to the path, then the robot stops at that moment.


Arduino Line Follower With Obstacle Detection Robot
Arduino Line Following Obstacle Avoidance Robot

Circuit Diagram

Arduino Line Follower Robot With Obstacle Detection Circuit Diagram
Arduino Line Follower Robot With Obstacle Detection Circuit Diagram

Components Required

  • Arduino UNO
  • L293D UNO Motor Driver Shield
  • HC-SR04 Ultrasonic Sensor
  • Infrared Sensor Module (x2)
  • Geared Motor (x4)
  • Wheels (x4)
  • 3.7V Li-Ion Battery (x2)
  • Battery Box
  • Chassis
  • Connector Wires

About Parts of Line Follower Robot


Arduino UNO
Arduino Nano

For the compact build, I choose Arduino Nano despite Arduino UNO. Arduino Nano is a small, flexible microcontroller board using an Atmega328p chip. It can also use as a substitute for UNO. All the functions are the same in these two boards. The size of its PCB is 18×45 mm. The clock speed is 16Mhz. Its input voltage is 5-12V. There are 30 pins including power pins, data pins, analog pins, serial pins on this board.

Ultrasonic Sensor

ultrasonic sensor
Ultrasonic Sensor

This is a sensor that can measure the distance of an object from the sensor position by ultrasonic sound waves. It sends ultrasonic waves of 40 KHz in the medium. If the waves are reflected on the object and bounce back to the sensor, it calculates the distance by calculating the travel time and speed of sound.

Infared Sensor

Infrared Sensor
Infrared Sensor

An infrared sensor module is an electronic device that emitted infrared rays for sensing. This sensor can sense any objects in the surroundings as well as measures the heat and motion of it. The working principle of this module is so easy. The IR transmitter sends the infrared rays and after a certain distance, it gets reflected by the object. These reflected rays get captured by the receiver present in this module. By this process, it captured data from the object.

L293D UNO Motor Driver Shield

L293D Motor Driver Shield
L298N Motor Driver

This is an L293D motor driver shield that can drive four motors, one stepper motor and two servo motors using Arduino UNO. Motors are arranged in a way called Half-Bridge. H-Bridge is an electronic circuit that enables a voltage to be applied across a load. It allows full control over a standard electric DC motor.

Note: I am using an L293D motor driver shield in this project, but you can also use an L298N motor driver as we use only four BO motors. But in the case of four BO motors for better result, we should use the L298N motor driver.

Working Principle of Arduino Line Follower Robot

According to the above circuit diagram, we notice that a microcontroller (Atmega328p) is used to communicate with the whole system for processing the robotics functions. First, we need to connect both Vcc and ground pins of the Arduino Nano with a 9V power supply. As we know this is the main source for operating the whole system.

After connecting the above connection, let’s connect the L293D motor driver shield onto the Arduino UNO. Four geared motors are connected to the outer terminal of the motor driver as shown in the circuit diagram. This is a powerful motor driver that can drive four 6V motors easily.

After that, let’s connect the right infrared sensor’s data pin to the A0 pin and the left infrared sensor’s data pin to the A1 pin of the Arduino. It helps to detect the black line according to the robot’s path and let it rotate in the correct direction.

Next, we need to connect an Ultrasonic sensor for detecting obstacles in front of its path. Then we need to connect the “Echo” and “Trig” pins to the A4 and A5 pins of the Arduino respectively. It collects the signal by throwing an ultrasound to any obstacles in front of it and then sends this signal by the “Trig” pin. Thus the Obstacle Avoiding Arduino Line Follower Robot works.

Conclusion of Arduino Line Follower Robot

Thus, the line follower obstacle avoidance robot is successfully designed and implemented. We can use the advanced big version of this robot in public transport. It will easily be operated without any other devices like smartphones, remote control, WiFi etc. This is fully automatic according to the path which we gave for it using the Arduino microcontroller.

Application of Arduino Line Follower Robot

  • In a time of automation generation to reduce labour efforts, it is necessary to develop such type of robot, that can be used in airports to carry equipment and luggage from one place to another.
  • They are very useful as they can work without any supervision i.e. they work like fully automatic vehicles.
  • With additional features like obstacle avoidance and other security measures, we can use obstacle avoiding line follower system in a driverless car.

Install NewPing Library

Click here to install the NewPing Library file.

Arduino line follower robot newping library install

After finishing the download open Arduino IDE software.

Sketch>> Include Library>> Add .ZIP Library>> Select NewPing ZIP which you download recently>> Open.

Arduino Code