1. Introduction
A line following robot is a simple autonomous robot that follows a path marked on the floor. The path is usually created using black tape on a white surface. The robot detects the line using sensors and automatically adjusts its direction to stay on the path.
In this project, we will build a DIY simple line following robot using Arduino and a single IR sensor module. Unlike advanced line follower robots that use multiple sensors, this design uses only one IR sensor, making it easy for beginners to understand and build.
The IR sensor detects the difference between black and white surfaces. White surfaces reflect infrared light, while black surfaces absorb it. The sensor sends this information to the Arduino microcontroller, which then controls the motors through a motor driver module.
When the robot detects the line, it changes its direction slightly to locate the path again. This creates a small zig-zag motion that allows the robot to follow the line.
This project is perfect for students, beginners, and robotics workshops because it demonstrates the basic concepts of sensors, motor control, and simple automation.
2. Components
The following components are required for building the robot.
• Arduino Uno
• IR Sensor Module – 1
• L298N Motor Driver Module
• DC Gear Motors – 2
• Robot Chassis with Wheels
• Caster Wheel
• Battery Pack (7.4V or 9V)
• Jumper Wires
3. Circuit and Connections
IR Sensor Connections
IR Sensor VCC → Arduino 5V
IR Sensor GND → Arduino GND
IR Sensor OUT → Arduino Pin 2
Motor Driver Connections
IN1 → Arduino Pin 8
IN2 → Arduino Pin 9
IN3 → Arduino Pin 10
IN4 → Arduino Pin 11
Motor Connections
Left Motor → Motor A output of L298N
Right Motor → Motor B output of L298N
Power Connections
Battery → L298N power input
Arduino can be powered through USB or Vin pin.
4. Circuit Working
The robot uses one IR sensor placed at the front of the robot chassis.
The sensor continuously emits infrared light toward the floor and measures the reflected light.
When the sensor is over a white surface, the infrared light is reflected back to the receiver. This causes the sensor output to become HIGH.
When the sensor moves over the black line, the infrared light is absorbed by the surface. As a result, very little light returns to the sensor and the output becomes LOW.
The Arduino reads this output signal and decides the robot movement.
If the robot is on a white surface, it moves forward.
If the robot detects the black line, it turns slightly to search for the path.
This continuous process allows the robot to follow the line using a zig-zag motion.
5. Code
#define SENSOR 2
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
void setup()
{
pinMode(SENSOR, INPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop()
{
int line = digitalRead(SENSOR);
if(line == HIGH)
{
forward();
}
else
{
searchLine();
}
}
void forward()
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void searchLine()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
6. Code Working
The program begins by defining the sensor pin and motor driver pins.
In the setup() function, the IR sensor pin is configured as an input, while the motor control pins are set as outputs.
Inside the loop() function, Arduino continuously reads the sensor value using the digitalRead() function.
If the sensor output is HIGH, it means the robot is on a white surface. The robot moves forward.
If the sensor output becomes LOW, it means the black line has been detected. The robot then turns slightly to search for the line.
Motor movement is controlled by sending digital signals to the L298N motor driver, which drives the two DC motors connected to the robot wheels.
This process repeats continuously, allowing the robot to move along the line.
7. Tips
• Adjust the IR sensor potentiometer for proper sensitivity.
• Keep the sensor about 5–10 mm above the floor.
• Use black tape on a white surface for best detection.
• Use 150–300 RPM gear motors for better control.
• Ensure that all wiring connections are secure.
8. Uses
• Robotics learning and workshops
• Engineering laboratory experiments
• Beginner autonomous robot projects
• Robotics competitions
• Industrial automated guided vehicle concepts
9. Conclusion
The Single IR Sensor Line Following Robot is a simple and effective project for learning the basics of robotics and automation. By using a single sensor, students can easily understand how robots detect paths and control their movement.
Although this robot is not as accurate as multi-sensor line followers, it is an excellent starting point for beginners. Once the basic concept is understood, the design can be upgraded to two or more sensors for better line tracking and smoother movement.
This project demonstrates how sensors, microcontrollers, and motors work together to create an autonomous system capable of performing tasks without human intervention.