What You Need
A line following robot needs one chassis, one microcontroller, one motor driver, two IR line sensors, one battery pack, and about ten jumper wires. That is the full list.
The Bot Scout starter BOM: a 2WD chassis kit, an Arduino Uno R3, an L298N dual H-bridge driver, two TCRT5000 IR sensor modules, a 6xAA battery holder, and a set of male-male and male-female jumper wires. Total cost $25-45 if sourced part by part.
For sourcing, see the where-to-buy-robot-parts guide. For a working pre-packaged kit, see the Arduino robot kits guide.
| Part | Typical model | Approx. price (USD) |
|---|---|---|
| 2WD chassis kit | Yellow BO gearmotor + wheel + castor + acrylic | $8-15 |
| Microcontroller | Arduino Uno R3 (or clone) | $10-25 |
| Motor driver | L298N dual H-bridge module | $4-8 |
| IR line sensor (x2) | TCRT5000 module | $2-4 each |
| Battery pack | 6xAA holder + switch | $3-6 |
| Jumper wires | Male-male and male-female | $4-8 |
Wiring
Wire the motor driver first. L298N: connect the battery + to VCC, battery - to GND, and 5V from the L298N to Arduino 5V. Connect IN1, IN2, IN3, IN4 to Arduino digital pins 5, 6, 9, 10. Connect the two motors to OUT1/OUT2 and OUT3/OUT4.
Wire the IR sensors second. Each TCRT5000 module has VCC, GND, and OUT. Connect VCC to Arduino 5V, GND to Arduino GND, and OUT to Arduino digital pins 2 and 3.
Verify power before flashing. The L298N gets warm; that is normal. If it gets hot, one motor lead is shorted.
The Arduino Sketch
The simplest line-follower is a two-sensor differential controller. Sensor sees black, that side's motor slows down; sensor sees white, that side's motor runs. Tape a black electrical-tape line on a white posterboard and drive.
Example core loop:
- int L = digitalRead(2); int R = digitalRead(3);
- if (L == 0 && R == 0) { forward(); } // both on line -> straight
- else if (L == 1 && R == 0) { turnLeft(); } // left off line -> steer left
- else if (L == 0 && R == 1) { turnRight(); } // right off line -> steer right
- else { stop(); } // both off line -> lost, stop
PID Tuning (When Two Sensors Are Not Enough)
The two-sensor version wobbles. The fix is more sensors (five is the standard array) and a PID loop that returns a continuous error signal instead of four discrete states.
Start with proportional only. Compute error = (weighted sensor position) - (center). Set motor speed as base ± Kp × error. Tune Kp until the robot follows without oscillating.
Add derivative next (Kd). Small D dampens oscillation. Integral (Ki) is rarely needed for line-following and usually causes windup.
Common Failures and Fixes
Robot drives one motor only: IN pin swapped, or one motor lead loose in the L298N screw terminal.
Robot spins in circles: one motor wired backwards. Swap the two wires at OUT1/OUT2 (or OUT3/OUT4).
Robot ignores the line: sensors too high off the ground. TCRT5000 wants to be 3-8 mm above the surface. Mount them lower.
Robot sees ghosts under fluorescent lights: add a small analog threshold, or move to modules with a digital comparator. For the next step up, see the obstacle-avoiding robot guide.
Bottom Line
A line-following robot is the standard afternoon project. Six parts, ten wires, thirty lines of code. When the two-sensor version wobbles, upgrade to five sensors and a PID loop.
Order the six parts, wire the L298N first, run the two-sensor sketch, then tune PID once you outgrow it.
FAQs
How much does it cost to build a line following robot?
Part by part, $25-45 for the chassis, Arduino Uno clone, L298N driver, two TCRT5000 sensors, battery pack, and jumper wires. A pre-packaged kit like the Elegoo Smart Robot Car v4 covers the same parts (plus more sensors) for around $70-90.
How many IR sensors does a line following robot need?
Two sensors are enough for a basic differential controller that follows a straight or gentle-curve line. Five sensors and a PID loop are the standard upgrade for smooth following on tighter curves.
What microcontroller is best for a line following robot?
An Arduino Uno R3 (or clone) is the standard choice. Any Arduino-compatible board with at least 4 digital pins and one PWM channel per motor will work, including the Nano, Micro, or an ESP32.
Why does my line following robot spin in circles?
One motor is wired backwards. Swap the two wires at that motor's L298N screw terminal (OUT1/OUT2 or OUT3/OUT4). The sketch still works; the polarity was reversed.