A small vehicle tracing a clearly marked route may look simple, but getting it to follow the path reliably is no child's play. Alongside the visible electronics are less obvious physical considerations, which can be harder to solve. Here is a practical guide to the essential ideas behind an effective line-following robot, from its sensors to the way its weight is distributed. Come learn how to build your own.
Known as trackers or followers, these electronic vehicles follow a line that forms a closed circuit on a surface that may be rough or uneven. The track is generally a line of varying width, usually no more than two centimeters, whose color contrasts with the surrounding floor: a white line on a black surface, or the reverse.
Line followers are a common first exercise in robotics and mechatronics, but their purpose is not limited to completing a course. Competitions put agility, speed, and even durability to the test. Suitable materials, sound electronic design, and careful mechanical design are all essential to a vehicle that works well. First, let’s see one in motion and consider what its parts do.
How a line follower works
At the heart of the system is the part that detects the line. Optical sensors mounted underneath the vehicle detect whether the track is beneath them and report that information to the robot’s main microcontroller. The controller then directs the motors as needed. As the vehicle moves, the sensors keep reading the line and sending their results to the controller, closing a continuous feedback loop.
A microcontroller is not essential in every design. Two effective sensors, placed on opposite sides of the line and connected to a suitable circuit, can switch the drive motors independently. That is enough to make a basic, simple line-following robot.
When both sensors detect that they are off the line, the motors keep running and the vehicle travels straight. At a bend—or if the robot drifts off course—one sensor detects the change and stops the motor on its side, while the other motor continues. This turns the vehicle until it finds the track again, producing an oscillating motion along the way.
Two sensors are just an illustration. In practice, robots may use three, four, or more than six sensors to determine their position relative to the track. With a microcontroller and carefully refined software, the system can adjust acceleration and braking—or switch the wheels off. Sensors are often mounted in several places, but the usual choice is as close as possible to the drive wheels, so they follow the line as accurately as they can.
Sensors ahead of the ones that determine direction can warn a microcontroller that the line has ended, allowing it to stop before the vehicle leaves the track. Rear sensors can provide a backup position check if the robot overshoots, helping it reverse along the route or turn around and travel back the other way.
Other sensors may sit well outside the track’s width. In competition circuits, crossings can require the robot to decide which way to turn. These sensors read directional markers that indicate the correct choice at the next intersection. The instruction is stored in the controller’s internal memory, ready to be consulted when the crossing appears.
Choosing and positioning the sensors
Picking the right components to detect the line is a key part of designing a line follower. One popular option is the CNY70 optocoupler, which contains an infrared emitting diode and a phototransistor that responds to the same wavelength. Its construction allows optical coupling by reflection when it is placed close to a reasonably flat, solid surface.
The phototransistor detects infrared light from the built-in LED. The signal level depends on the distance from the surface: the farther away the sensor is, the weaker the recovered signal. Surface color matters too. White reflects more light than black, so at the right height the sensor can distinguish a white line from a dark track—or the reverse.
The phototransistor’s output is analog, meaning it changes as the distance between the sensor and reflective surface varies. That can make it difficult to get a clear yes-or-no indication of whether the robot is over the line. Two straightforward solutions are a voltage comparator or, more commonly, a Schmitt-trigger inverter such as the CD40106 CMOS chip. Either approach produces a definite signal for each sensor.
The resistor values are suggested values, though they are commonly used. Include jumper JP1 in the circuit: this hardware arrangement saves microcontroller code when the track colors are reversed—for example, a black line on a white surface instead of a white line on black. The best sensor arrangement depends on practical results from the vehicle’s mechanical design. There is no single universally effective layout; experiment with the mechanical and dynamic setup until it performs well.
Motors and wheels
The usual choices are conventional DC motors, stepper motors, and servomotors. Each has advantages and drawbacks. Ordinary DC motors can deliver very high top speed, potentially making them the fastest option, but they require extra hardware and code compared with servos. To slow down at a curve or intersection, a DC motor needs its polarity reversed; with servomotors, a simple software instruction can perform the operation.
DC motors also react more slowly than servos, which can start and reach speed almost instantly. Adding a gearbox to make a conventional motor useful as a drive unit adds mechanical complexity and takes time that might otherwise go toward refining the software. For these reasons, many line-following robot builders choose servomotors.
Stepper motors occupy a middle ground: they need additional hardware too, and their high power consumption makes them less common. They are found in printers and fax machines. Wheel diameter also matters. Small wheels provide strong initial acceleration and a successful start, while larger wheels can deliver a higher top speed, an important factor in a race. Wide wheels grip better in corners; narrow ones reduce friction and can increase top speed.
Batteries
Choosing the right energy store is important as well. Battery life can determine whether a robot finishes a competition and how well it performs; most events do not allow competitors to replace the battery, so the same one must last throughout. Fortunately, lithium-ion batteries are widely available. They offer an excellent balance of weight and energy capacity, long operating life, and short charging times, so this component generally needs little further analysis or testing.
Putting the design into practice
The sensor choice and, especially, its position on the vehicle deserve careful attention. You can use any infrared LED and photodetector if they deliver the results you need; the CNY70 is simply a common example. Reflective optocouplers can also be salvaged from old VHS recorders, beneath each reel, or from older cassette players.
Don’t expect to build the robot of your dreams and get extraordinary results on the first try. Electronics, mechanics, and physics always bring surprises and obstacles to overcome. Don’t be discouraged by early failures. Every successful line follower you see in videos is the result of many sleepless nights and plenty of demoralizing setbacks.
That covers what we consider the most important theory behind building a line-following robot. The practical work is up to you: bring patience, effort, and dedication. And, of course, we hope to see your robot showing off on YouTube soon.