What is a line follower robot?
A line follower robot is a small autonomous vehicle that follows a dark line on a lighter surface. It does this by reading infrared (IR) sensors near the front and changing the speed of its left and right motors. You do not need GPS, Wi-Fi or a camera: a basic Arduino, two sensors and a motor driver are enough to learn the core idea.
This guide takes you from the parts and wiring checks to sensor logic, first movement tests and speed tuning. It is written for beginners building a two-wheel robot for a school project, makerspace or robotics competition. The examples use an Arduino Uno, two digital IR sensors and an L298N motor driver; the same principles apply to similar boards and drivers.
How a line follower works
The robot repeats three simple steps in a continuous loop:
1. Detect
The infrared (IR) sensors measure whether the track below each sensor is dark or light.
2. Decide
The Arduino reads both sensor outputs and decides whether to drive straight or correct left or right.
3. Drive
The motor driver applies the requested direction and speed to the left and right motors.
Then the sensors are read again. Fast, small corrections help the robot stay on the line; excessive speed can make it miss a curve before it reacts.
1. Parts you need
- Arduino Uno or compatible board
- Two digital IR reflectance sensor modules (or a three-sensor array for better line-position information)
- Two geared DC motors, wheels, chassis and a caster wheel
- L298N motor driver module, if suitable for your motors, or a more efficient driver matched to motor stall current
- Battery pack matched to the motors and driver
- Switch, jumper wires, mounting hardware and a multimeter
Before choosing the driver: check the motor’s rated voltage and stall current. The L298N is widely used in beginner builds, but it loses more voltage and produces more heat than modern MOSFET drivers. The actual current capability depends on the module, cooling and wiring.
2. Understand the robot layout
Place the sensor board at the front, facing down at the track. The sensors should be close enough to detect a clear contrast, but not so close that they scrape the surface. Keep their height consistent. Put the two drive wheels on the motor axle and the caster at the opposite end.
Top-view layout (conceptual)
wheelChassisRight
wheel
Not to scale. Actual sensor spacing and sensor-to-axle distance depend on track width, chassis geometry and sensor module.
Keep the sensor line ahead of the wheel axle, but do not place it unnecessarily far forward. A large sensor-to-axle distance means the robot continues travelling after the sensors detect a curve, which can contribute to overshooting.
3. Wiring checklist
Use the pinout printed on your own driver board; module layouts can differ. This table is an example for an Arduino Uno and a typical L298N module.
| Part | Example connection | Purpose |
|---|---|---|
| Left IR sensor OUT | Arduino D12 | Reads the left side of the track |
| Right IR sensor OUT | Arduino D2 | Reads the right side of the track |
| L298N ENA | Arduino D9 (PWM) | Controls left motor speed |
| L298N IN1 / IN2 | Arduino D5 / D4 | Sets left motor direction |
| L298N ENB | Arduino D10 (PWM) | Controls right motor speed |
| L298N IN3 / IN4 | Arduino D6 / D7 | Sets right motor direction |
| Motor supply | Driver motor-power input | Powers motors at their rated voltage |
| Ground | Arduino GND ↔ driver GND ↔ sensor GND | Provides a common reference |
Remove the ENA/ENB jumpers only if you intend to control speed with Arduino PWM on those pins. Do not power motors from the Arduino 5 V pin. Use a suitable motor supply, connect grounds correctly, and disconnect power before changing motor wiring. Check the specific module’s logic-supply and regulator instructions before powering it.
4. Calibrate the sensors before driving
- Raise the drive wheels so the robot cannot run away during the first test.
- Power the sensors and open the Arduino Serial Monitor or observe each module’s indicator LED.
- Move each sensor over the white surface and then over the black line.
- Record the output for each surface. Some modules output LOW on black and HIGH on white; others behave in the opposite way.
- Adjust the module’s threshold potentiometer if it has one, then repeat the test under the same lighting and sensor height you will use on the track.
Never assume that “LOW means black” without testing your exact sensor. Incorrect assumptions reverse the steering logic.
5. Movement logic: what should happen?
| Left sensor | Right sensor | Typical response |
|---|---|---|
| Line detected | Line detected | Continue straight, if this pattern means the line is centred for your sensor arrangement |
| Line detected | Line missed | Apply a correction based on which side of the line the robot is drifting toward |
| Line missed | Line detected | Apply the opposite correction |
| Line missed | Line missed | Slow down and search carefully, or stop if the line has been lost |
Control workflow
- Read both sensors — sample their digital outputs.
- Classify the track position — centred, drifting left/right, or line lost.
- Choose motor outputs — straight motion, differential steering, or a controlled search.
- Apply PWM and direction — send commands through the motor driver.
- Repeat quickly — read again and correct as the robot moves.
With only two sensors, some patterns can be ambiguous, especially on wide lines or intersections. A three- or five-sensor array provides more information about where the line sits under the robot.
6. Tune speed without losing the line
Start with a low PWM value on a straight section, then raise it in small steps. Arduino PWM values commonly range from 0 to 255, but a particular motor may not start reliably at low values. There is no universal “correct” speed: battery voltage, motor mismatch, wheel grip, chassis weight, sensor height and track contrast all matter.
- For straight sections: use similar left and right speeds after compensating for any motor mismatch.
- For turns: reduce the inner wheel and keep the outer wheel faster; on tight corners, slow both motors.
- If it overshoots: reduce straight speed first, then increase steering correction gradually.
- If it wobbles: reduce correction strength or speed and check sensor spacing and alignment.
- For smoother steering: consider a three- or five-sensor array and a proportional or PD controller after basic logic works reliably.
Change one variable at a time and test the same section of track several times. Record the PWM values, battery condition and result; this makes tuning much more repeatable.
7. Troubleshooting checklist
- Robot veers on a straight line: check sensor calibration, wheel alignment and left/right motor speed differences.
- It overshoots corners: lower speed before sharp turns, check the sensor-to-axle distance and strengthen corrections in small steps.
- Sensor readings flicker: clean the sensor face, secure wires, keep height consistent and check ambient light.
- One motor is much slower: measure the battery and motor-driver output under load; inspect terminals, motor condition, driver heating and PWM commands.
- Arduino resets when motors start: check for voltage dips and electrical noise; use an appropriate motor supply, common ground and suitable power wiring.
- Robot spins when it loses the line: make the lost-line search deliberate and bounded, rather than continuing the last turn indefinitely.
8. Safety and final test
Secure the battery and wires so they cannot catch in the wheels. Keep fingers away from the drivetrain, lift the wheels for the first motor-direction test, and disconnect the battery before rewiring. Stop immediately if the driver, battery or wiring becomes unusually hot.
Before a full run, confirm all four basics: the sensors distinguish black from white, both motors rotate in the intended direction, the battery remains stable under load, and the robot can follow a straight line at low speed. Only then move on to curves and faster runs.
Explore more robotics projects
Browse Pandey Electronics for prototyping boards, sensors, motor drivers and robotics parts; compare electrical specifications before ordering. You may also find the Arduino and ESP32 parts checklist useful when planning your next build.
Key takeaway: reliable line following comes from verified sensor logic, sensible steering, stable power and systematic testing—not simply running the motors at maximum speed.
Image credit: The featured line-following robot photograph is by Marcmccomb, Wikimedia Commons, CC BY-SA 3.0. Its source records GPS coordinates (33.304167, -111.881389); that is the photo location, not Pocharam or Hyderabad. View the original and license.