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.
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
| Item | Value |
|---|---|
| Difficulty | ⭐⭐⭐ Intermediate |
| Build Time | 4–8 Hours |
| Supply Voltage | 6–12 V DC |
| Control | Microcontroller |
| Drive System | Two 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
| Quantity | Component |
|---|---|
| 1 | Arduino Nano, Uno or ESP32 |
| 2–5 | Infrared Line Tracking Sensors (TCRT5000) |
| 1 | L298N or TB6612FNG Motor Driver |
| 2 | DC Gear Motors |
| 2 | Robot Wheels |
| 1 | Caster Wheel |
| 1 | Battery Holder (18650 or AA Cells) |
| 1 | Robot 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
- Check all wiring connections.
- Verify motor rotation directions.
- Calibrate the infrared sensors.
- Place the robot on a simple straight track.
- Adjust motor speeds if necessary.
- Test curves and intersections.
- Fine-tune the control algorithm.
- 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.