Source: https://mokxi.com/teachers/plans/build-line-follower-racer
Updated: 2026-11-19

Lesson plan

# 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.

3 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## 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.

Chapter 1. About 2 h

## See the line

Infrared, comparators and five bits, then one number in millimeters a controller can steer by.

Lesson | Time | What students do

Sensor arrays Five 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

- Run it
- How one sensor sees
- Two at once
- Five bits, one number
- Lost
- A bar across

Line position Turn 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

- A weighted average
- The other side
- Predict it
- Steps, not a slope
- Where it goes blind

### 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".

Chapter 2. About 1 h 50 min

## 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 driver A 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

- Run it
- How fast is full
- Spin on the spot
- Brake is not coast
- Coast

P then PD The 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

- Run it
- P: steer by the error
- Turn it up, and hit the wall
- D: steer by the change
- D brakes the turn

### 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".

Chapter 3. About 2 h 15 min

## Race

Speed against grip, laps timed to the hundredth, and a three lap race with a failsafe.

Lesson | Time | What students do

Speed vs grip Faster 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

- Base speed
- Grip is physics
- Slow in the bends
- A tired pack

Lap timing A 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

- The start line
- One lap
- How far is a lap
- The best lap

Project: a race track Turn 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

- Lay out the track
- Three laps and the flag
- Your gains in the code
- A failsafe
- Race day

### 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".

Your class

## 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.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
