Building line-following robots
CostLow to Medium
Includes: TCRT5000 sensor array or a full Arduino line follower kit. Example: A full line follower kit costs €20-35.
What it is
A crude line follower lurches left and right across the tape like a learner driver overcorrecting. A well-tuned one glides down the same line as if it is on rails. The hardware can be identical; the entire difference lives in the control algorithm, and improving that algorithm is a hands-on crash course in control theory.
A line-following robot uses reflectance sensors to detect and follow a line, usually black tape on a white floor, as it drives. It is one of the most instructive beginner robotics projects precisely because it poses a real, unforgiving control problem: keep the robot centred on the line using sensor feedback, and the quality of your solution is immediately visible in how the robot behaves. There is nowhere to hide a sloppy approach.
The hardware is modest. A reflectance sensor array, three to five sensors spaced across the line width, sits beneath the robot, each reading high on white and low on black. From those readings you calculate a weighted position telling you how far off-centre the robot has drifted. The crudest control, called bang-bang, turns hard one way or the other depending on which sensor sees black, and it works but wobbles constantly.
The leap to smooth driving is PID control. You compute an error, how far from centre, multiply it by a proportional gain, add a derivative term to damp oscillation, and add a small integral term to eliminate steady drift, then feed the result to the two motors as a speed difference. Tuning the gains is the craft. The reliable order is to raise the proportional gain until the robot just oscillates on the line, then add derivative until the oscillation settles, then a touch of integral, and tuning out of that order produces unpredictable results.
This is also where robotics gets competitive. Line-follower races, common across Europe, reward the fastest robot through a track, which demands more sensors, faster loops, and finely tuned gains, so the educational robot is one race away from a genuine engineering challenge.
How it works
The mistake that produces every wobbling first line-follower is jumping straight to crude on-off steering, where the robot slams full-left or full-right and zigzags down the line like a learner overcorrecting. The path past this is PID control, but you build up to it deliberately rather than starting there. Understand the wobble is a control problem, not a hardware fault, and the whole project becomes a hands-on lesson in control theory.
Mount a reflectance sensor array, a TCRT5000 set of three to five sensors spaced across the line width, beneath the front of the robot. Each reads high on the white surface and low on the black line. Calculate a weighted position from which sensors see black and where they sit, giving you a single number for how far off-centre the robot has drifted, the error. With three sensors you get rough position; with five you get the resolution for genuinely smooth following.
Now layer the control. Bang-bang steering, turn hard toward the line, works but wobbles. Proportional control multiplies the error by a gain so the correction scales with how far off you are, which smooths it considerably. Adding a derivative term, responding to how fast the error is changing, damps the oscillation, and a small integral term clears any steady drift. The tuning order is fixed and matters: raise the proportional gain until the robot just starts to oscillate on the line, then add derivative until that oscillation settles, then a touch of integral last.
What actually happens when people tune out of order, adding integral before the proportional and derivative terms are stable, is wild unpredictable behaviour that looks like a broken robot. A well-tuned PID follower on a smooth track exceeds two metres a second, fast enough that the sensor and control loop are running flat out.
Benefits
What you need
Here's what to gather before you start. The essentials are marked.
Some links below are affiliate links. As an Amazon Associate, trylii.com earns from qualifying purchases, at no extra cost to you.
FAQs
Sensors underneath detect the contrast between the line and the floor, and the robot steers to stay over it. Reflectance sensors read dark versus light, so a black line on white tells the robot where the line is relative to its centre. If the line drifts left, the robot turns left to recentre. With two or more sensors, this becomes a constant small correction that keeps it tracking the path.
It is overcorrecting, turning too hard each time it drifts. With simple "if left sensor sees line, turn left" logic, the robot lurches side to side because it only ever makes full turns. The cure is proportional control: the further off-centre the line is, the harder it steers, and small drifts get small corrections. That single change turns frantic zigzagging into a smooth glide along the line.
Two works, but three to five tracks far better. Two sensors can tell left from right, which is enough for gentle curves. An array of three to five reads the line's position more precisely, handles sharp turns, and lets you implement proper proportional steering. I started with two to learn the idea, then moved to a five-sensor array once the jerky two-sensor behaviour frustrated me on tight corners.
A lot, and it catches people out at competitions. Reflectance sensors read contrast, so a shiny floor, a shadow, or changing room light can confuse them. Calibrating the sensors to the actual track before running, rather than relying on default thresholds, fixes most problems. I always run a quick calibration pass on the specific surface, because a robot tuned on my desk often fails on a different floor.