Intermediate Project

Build a Line Following Robot

A line-following robot is one of the most popular educational robotics projects. It automatically follows a dark or light line on the floor using infrared sensors, making it an excellent introduction to autonomous robots, sensor technology and motor control. This project explains how to build a reliable line-following robot using an Arduino, ESP32 or other microcontroller with infrared reflective sensors and DC gear motors.

Line Following Robot

Project Overview

The robot continuously scans the surface beneath it using infrared sensors.

When the sensors detect the line, the microcontroller adjusts the speed of the left and right motors to keep the robot centred on the path.

This process occurs many times each second, allowing the robot to follow straight lines, curves and intersections smoothly.

Project Difficulty

ItemValue
Difficulty⭐⭐⭐ Intermediate
Build Time4–8 Hours
Supply Voltage6–12 V DC
ControlMicrocontroller
Drive SystemTwo DC Gear Motors

Main Sections

Section Function
Infrared Sensors Detect the line.
Microcontroller Processes sensor data.
Motor Driver Controls motor direction and speed.
DC Gear Motors Move the robot.
Battery Pack Provides power.
Robot Chassis Supports all components.

Typical Components

QuantityComponent
1Arduino Nano, Uno or ESP32
2–5Infrared Line Tracking Sensors (TCRT5000)
1L298N or TB6612FNG Motor Driver
2DC Gear Motors
2Robot Wheels
1Caster Wheel
1Battery Holder (18650 or AA Cells)
1Robot Chassis

How the Robot Works

Infrared LEDs illuminate the surface beneath the robot.

White surfaces reflect more infrared light than black surfaces. The phototransistors measure the reflected light and send the information to the microcontroller.

If the line moves toward one side of the robot, the controller adjusts the motor speeds using PWM so that the robot turns back toward the line.

This continuous correction allows the robot to follow the path accurately.

Basic Control Logic

Sensor Condition Robot Action
Centre Sensor on Line Move Forward
Left Sensor on Line Turn Left
Right Sensor on Line Turn Right
All Sensors White Search for Line
All Sensors Black Stop or Execute Junction Routine

Applications

  • Educational robotics.
  • STEM learning.
  • Warehouse transport robots.
  • Factory automation.
  • Autonomous guided vehicles (AGVs).
  • Robot competitions.
  • Research projects.
  • Electronics training.

Testing

  1. Check all wiring connections.
  2. Verify motor rotation directions.
  3. Calibrate the infrared sensors.
  4. Place the robot on a simple straight track.
  5. Adjust motor speeds if necessary.
  6. Test curves and intersections.
  7. Fine-tune the control algorithm.
  8. Measure battery operating time.

Troubleshooting

Problem Possible Cause
Robot leaves the line Sensors incorrectly positioned or poorly calibrated.
Robot spins continuously Motor wiring reversed.
Sensors do not detect the line Incorrect sensor height or unsuitable surface.
Motors do not move Battery discharged or motor driver fault.
Robot oscillates Motor speed too high or control parameters need adjustment.

Project Improvements

  • Use PID control for smoother steering.
  • Add Bluetooth configuration.
  • Display sensor values on an OLED screen.
  • Detect intersections automatically.
  • Store track maps in memory.
  • Add obstacle detection using ultrasonic sensors.
  • Use brushless motors with encoders.
  • Control the robot via Wi-Fi for diagnostics.

Skills Learned

  • Infrared sensing.
  • Motor control using PWM.
  • Microcontroller programming.
  • Robot navigation.
  • Autonomous control systems.
  • Basic robotics.

Safety Notes

  • Ensure all moving parts are securely mounted.
  • Keep wires clear of the wheels.
  • Use batteries with adequate current capability.
  • Switch off the robot before making wiring changes.
  • Test the robot in an open area free of obstacles.

Key Points

  • A line-following robot uses infrared sensors to detect a path.
  • The microcontroller continuously adjusts motor speeds to stay on the line.
  • PWM enables smooth steering and speed control.
  • PID control can significantly improve tracking accuracy.
  • Line-following robots provide an excellent introduction to autonomous robotics and embedded programming.

Next Project

Continue by building an Obstacle Avoiding Robot, where ultrasonic sensors allow the robot to detect and avoid obstacles while navigating autonomously.

Next Project → Obstacle Avoiding Robot