How-to · Intermediate · 3 min read
Line Follower Robot
Sensors, Wiring and Control Logic
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
A line follower uses a row of infrared reflective sensors (TCRT5000 type) under the robot to see a black line on a white floor, and steers two DC motors to keep the line centred. Start with two or three sensors and simple left/right logic, then move to a 5-sensor array and PID control for smooth, fast following. Power the motors through a driver from their own battery.
Key specs at a glance
- Sensors
- 2 to 8 TCRT5000 reflective IR sensors, 5 to 15 mm above the floor
- Motors
- 2 x BO or N20 gear motors, 100 to 300 RPM
- Driver
- TB6612FNG or L298N
- Controller
- Arduino Uno/Nano or ESP32
- Power
- 2S Li-ion (7.4 V) or 6 x AA for motors; shared ground with the controller
- Line
- Black tape 18 to 25 mm wide on white, or the reverse
Parts list
Shop this list3 of 4 found in our store · ₹71,309
A 2WD chassis with two BO motors and a caster, or an N20-based mini chassis.Round 2WD Mini Robot Chassis₹379Closest match, check the specs- 2, 3 or 5 TCRT5000 sensor modules, or a Cytron LSS05 / Pololu QTR-5 array.Find this part
A motor driver: TB6612FNG for N20 and BO motors on 6 to 8 V, L298N for 12 V motors.TB6612FNG Dual Motor Driver Module₹130Closest match, check the specs
An Arduino Uno or Nano (or ESP32), a 2S Li-ion pack or 6 x AA, and jumper wires.Kikobot C1 6-Axis Robotic Arm for Education and Research₹70,800
How the sensors see the line
Each TCRT5000 shines IR at the floor and measures the reflection. White reflects strongly, black tape reflects little. The module's comparator outputs HIGH or LOW (the direction depends on the module) and most also give an analog value. Mount the sensors 5 to 15 mm above the floor, spaced slightly narrower than the line so at least one sensor sees the line in a turn.
Simple three-sensor logic
| Left | Centre | Right | Action |
|---|---|---|---|
| White | Black | White | Drive straight |
| Black | Black | White | Turn left (slow left motor) |
| Black | White | White | Turn left hard |
| White | Black | Black | Turn right |
| White | White | Black | Turn right hard |
| White | White | White | Lost: keep last turn, or stop |
| Black | Black | Black | Junction or finish line: stop or count |
- White
- Centre:
- Black
- Right:
- White
- Action:
- Drive straight
- Black
- Centre:
- Black
- Right:
- White
- Action:
- Turn left (slow left motor)
- Black
- Centre:
- White
- Right:
- White
- Action:
- Turn left hard
- White
- Centre:
- Black
- Right:
- Black
- Action:
- Turn right
- White
- Centre:
- White
- Right:
- Black
- Action:
- Turn right hard
- White
- Centre:
- White
- Right:
- White
- Action:
- Lost: keep last turn, or stop
- Black
- Centre:
- Black
- Right:
- Black
- Action:
- Junction or finish line: stop or count
Arduino code: three sensors, bang-bang control
const int L = A0, C = A1, R = A2; // sensor digital outputs
const int ENA = 5, IN1 = 7, IN2 = 8; // left motor
const int ENB = 6, IN3 = 9, IN4 = 10; // right motor
const int BASE = 150; // 0 to 255
void motors(int left, int right) {
digitalWrite(IN1, left >= 0); digitalWrite(IN2, left < 0);
digitalWrite(IN3, right >= 0); digitalWrite(IN4, right < 0);
analogWrite(ENA, abs(left)); analogWrite(ENB, abs(right));
}
void setup() {
for (int p : {L, C, R}) pinMode(p, INPUT);
for (int p : {ENA, IN1, IN2, ENB, IN3, IN4}) pinMode(p, OUTPUT);
}
void loop() {
bool l = digitalRead(L) == LOW; // LOW on black for most TCRT5000 modules
bool c = digitalRead(C) == LOW;
bool r = digitalRead(R) == LOW;
if (c && !l && !r) motors(BASE, BASE);
else if (l) motors(BASE / 3, BASE);
else if (r) motors(BASE, BASE / 3);
else motors(BASE / 2, BASE / 2); // lost: creep forward
}Smoother and faster: PID with a 5-sensor array
With five analog sensors, compute a weighted position from -2000 to +2000 (0 = centred). Error = position; correction = Kp x error + Kd x (error - lastError). Left speed = base - correction, right = base + correction. Start with Kp around 0.05 and Kd = 0, raise Kp until the robot oscillates, then add Kd (10 to 20 x Kp) to damp it. Ki is rarely needed. Calibrate by sweeping the robot across the line at start-up and storing each sensor's min and max.
Tuning and troubleshooting
base speed too high for the logic; lower it or add PID.
sensors too far apart, or too fast. Space them closer and slow on sharp turns.
sunlight or glossy floors. Shield the sensors and test on matte white paper.
motors differ; add a trim value, or use encoders.
shared weak battery; add a capacitor on the driver supply or separate the supplies.
Try it: Wheel speed calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Mounting sensors too high or too far apart.
- Running the Arduino and motors from a 9 V PP3 battery.
- Hard-coding thresholds instead of calibrating on the actual floor.
- Driving straight at full speed with bang-bang control.
- Ignoring the sensor module's polarity (LOW vs HIGH on black).
Frequently asked questions
Which sensor is best for a line follower?
TCRT5000 reflective sensors, either as separate modules or a 5-channel array such as the Cytron LSS05 or Pololu QTR-5A. Arrays make PID control easier.
How many sensors does a line follower need?
Two or three for a basic robot; five or more for fast, smooth following and junction detection.
What motors should I use?
Geared DC motors at 100 to 300 RPM: BO motors for cheap chassis, N20 micro metal gear motors for small fast robots. Match the driver to the stall current.
Does a line follower need PID?
Not for a start. Simple left/right logic works. PID makes it faster and smoother, which matters in competitions.
Why does my line follower work on paper but not on the floor?
Floor reflectivity differs: glossy or dark floors confuse IR sensors. Calibrate on the real surface and shield the sensors from ambient light.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 35 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.




