Demonstration deployment — catalogue, prices and customers are sample data. Payments run in labelled sandbox mode.What this means
roboticsdebugging

Why your line follower oscillates (and how to fix it)

Sadman Sakib ·

The wobble is almost always one of three things.

A robot that swings across the line instead of tracking it is showing you a control problem, not a wiring problem.

1. Uncalibrated sensors

Reflectance readings change with ambient light, surface and battery voltage. A threshold hard-coded on Tuesday afternoon fails on Wednesday morning.

Sweep the sensors across the line at startup, record the minimum and maximum per sensor, and normalise every reading against that range.

2. All P, no D

Proportional control alone always overshoots: by the time the error is zero, the robot is already turning. The derivative term is what anticipates the crossing and starts straightening early.

Start with D at roughly four times P and tune from there. If it judders, the derivative is amplifying sensor noise — filter the reading before differentiating.

3. A loop with no fixed period

If the control loop runs whenever it can, its period changes with whatever else the code is doing — and your gains are tuned to a period that no longer exists. Fix the interval with a timer.

Ordering the fix

Calibrate first. Most "PID problems" disappear at that step, because the loop was reacting to readings that meant something different from one run to the next.

More like this

Choosing your first microcontroller

An 8-bit AVR board or a Wi-Fi board? A decision that takes two minutes if you ask the right question.

A final-year hardware project that survives exam season

Integrate early, order long-lead parts in week three, and keep one page of truth.

How to read a datasheet without reading all of it

Four sections answer almost every question you actually have.