Build a line-following racer lesson plan
A line-following race car taught as real control engineering: a five-sensor array, the line’s position in millimeters, differential drive on a TB6612, P then PD steering, speed against grip, and lap timing with a wheel encoder.
Objectives and materials
By the end, students can
- Infrared, comparators and five bits, then one number in millimeters a controller can steer by.
- Two wheels through an H-bridge, then a PD controller that turns the error into wheel commands.
- Speed against grip, laps timed to the hundredth, and a three lap race with a failsafe.
Materials for the whole unit
- Arduino Uno R3
- Battery: AA, coin cell, LiPo
- DC motor x 2
- Line tracker, 5 channel
- Motor driver, TB6612FNG
- Robot car chassis, 2WD
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
See the line
Infrared, comparators and five bits, then one number in millimeters a controller can steer by.
| Lesson | Time | What students do |
|---|---|---|
| Sensor arraysFive TCRT5000 reflective sensors in a row are the racer’s eyes. See how infrared light, a phototransistor and a comparator turn black tape into a high pin, and read all five as one number. | 65 min |
|
| Line positionTurn five on and off sensors into one number a controller can use: the line’s position in millimeters, by a weighted average. Find out how fine it can see, and where it goes blind. | 55 min |
|
Materials
- Arduino Uno R3
- Battery: AA, coin cell, LiPo
- DC motor x 2
- Line tracker, 5 channel
- Motor driver, TB6612FNG
Check for understanding
Each student finishes "Line position" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Where it goes blind".
Steer
Two wheels through an H-bridge, then a PD controller that turns the error into wheel commands.
| Lesson | Time | What students do |
|---|---|---|
| Two wheels and a driverA line follower steers like a tank: two wheels at different speeds. Drive two gearbox motors through a TB6612FNG, spin on the spot, and see why its brake is not a coast. | 55 min |
|
| P then PDThe controller that makes it a racer. Steer in proportion to the error, see the wheel commands saturate, then add a derivative term that brakes the turn before it overshoots. | 55 min |
|
Materials
- Arduino Uno R3
- Battery: AA, coin cell, LiPo
- DC motor x 2
- Line tracker, 5 channel
- Motor driver, TB6612FNG
- Robot car chassis, 2WD
Check for understanding
Each student finishes "P then PD" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "D brakes the turn".
Race
Speed against grip, laps timed to the hundredth, and a three lap race with a failsafe.
| Lesson | Time | What students do |
|---|---|---|
| Speed vs gripFaster is not always quicker. Put real numbers on base speed, the corner speed tires can hold, slowing down in the bends, and the pack that gets slower as it empties. | 40 min |
|
| Lap timingA bar across the track starts the clock. Time each lap to the hundredth, measure it in millimeters with the wheel encoder, and keep the best. | 40 min |
|
| Project: a race trackTurn the racer into a race car: a race of three laps that stops at the flag, your own tuned gains in the code, a failsafe for a lost line, and a race day run. | 55 min |
|
Materials
- Arduino Uno R3
- Battery: AA, coin cell, LiPo
- Line tracker, 5 channel
- Motor driver, TB6612FNG
- Robot car chassis, 2WD
Check for understanding
Each student finishes "Project: a race track" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Race day".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.