Skip to main content
Robotics Projects

Line Follower Robot

Build a robot that follows a black line on a white surface using IR sensors and Arduino.

RoboLand10 Minutes

What is a Line Follower Robot?

A line follower robot is one of the most popular beginner robotics projects. It is a robot that detects and follows a line drawn on the floor.

The line is usually a black tape on a white surface. The robot uses infrared sensors to detect the line and adjusts its movement to stay on track.

Line follower robots are used in real-world applications like automated guided vehicles in factories and warehouses.

Components Required

You will need:

  • Arduino Uno
  • 2 IR sensor modules
  • L298N motor driver
  • 2 DC motors with wheels
  • 1 caster wheel
  • Robot chassis
  • 9V battery or battery pack
  • Jumper wires
  • Black electrical tape (for the line)
  • White surface (paper or floor)

How It Works

The robot uses two IR sensors placed at the front, one on the left and one on the right side of the line.

IR sensors emit infrared light and measure how much light is reflected back.

White surfaces reflect more light (sensor reads HIGH), while black surfaces absorb light (sensor reads LOW).

Movement Logic

  • Both sensors on white — move forward (line is between sensors)
  • Left sensor on black — turn left (line has moved left)
  • Right sensor on black — turn right (line has moved right)
  • Both sensors on black — stop (end of line or intersection)

Step 1: Build the Chassis

Attach the two DC motors to the rear of the chassis with wheels.

Attach the caster wheel to the front for balance.

Mount the Arduino board on top of the chassis.

Mount the L298N motor driver next to the Arduino.

Mount the two IR sensors at the front bottom of the chassis, about 1-2 cm above the ground.

Space the sensors about 2-3 cm apart, with the line passing between them.

Step 2: Wiring

Connect the components as follows:

  • IR Sensor 1 OUT pin to Arduino pin 2
  • IR Sensor 2 OUT pin to Arduino pin 3
  • IR Sensor VCC pins to Arduino 5V
  • IR Sensor GND pins to Arduino GND
  • Motor A to L298N OUT1 and OUT2
  • Motor B to L298N OUT3 and OUT4
  • L298N IN1 to Arduino pin 5
  • L298N IN2 to Arduino pin 6
  • L298N IN3 to Arduino pin 9
  • L298N IN4 to Arduino pin 10
  • Battery to L298N 12V and GND
  • L298N GND to Arduino GND

Step 3: Programming Logic

The Arduino code reads the IR sensor values and controls the motors accordingly.

In the setup() function, set the sensor pins as INPUT and motor pins as OUTPUT.

In the loop() function, read both sensor values and use if-else conditions to control movement:

  • If both sensors read HIGH (white) — set both motors forward
  • If left sensor reads LOW (black) — stop left motor, run right motor (turn left)
  • If right sensor reads LOW (black) — run left motor, stop right motor (turn right)
  • If both sensors read LOW (black) — stop both motors

Upload the code to Arduino and test on your track.

Step 4: Create the Track

Use black electrical tape on a white surface to create your track.

Start with simple straight lines and gentle curves.

Make the tape about 2-3 cm wide for reliable detection.

Avoid sharp 90-degree turns for beginners. Use smooth curves instead.

As you improve, you can add tighter turns and intersections.

Troubleshooting

  • Robot does not follow the line — adjust sensor height (should be 1-2 cm above ground)
  • Robot overshoots turns — reduce motor speed in the code
  • Sensors give wrong readings — adjust the sensitivity potentiometer on the IR module
  • Robot moves in wrong direction — swap motor wires on the L298N
  • Robot is unstable — check if the caster wheel moves freely

!Key Points

  • Line follower robots use IR sensors to detect black lines on white surfaces
  • Two IR sensors are placed at the front to track the line position
  • The Arduino reads sensor values and controls motors to follow the line
  • Start with simple tracks and gradually increase difficulty
  • This project teaches sensor reading, motor control, and basic programming logic

Build More Robots