Source: https://mokxi.com/learn/path/build-line-follower-racer
Updated: 2026-11-20

All paths

# Build a line-following racer

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.

Arduino Uno R3 Free 7 lessons 6 h 3 chapters 2,001 XP Robotics · Intermediate +150 XP

0 of 7 done

Start the course free Sensor arrays Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 3 chapters, about 6 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### 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.
Open it in the simulator

Chapter 2 project

### 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.
Open it in the simulator

Chapter 3 project

### 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.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## See the line

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

Open 236 XP

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

0 of 6 steps

Start What is in it

Project Locked 410 XP

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

0 of 5 steps

4 questions, graded as you go.

Chapter 2

## Steer

Two wheels through an H-bridge, then a PD controller that turns the error into wheel commands.

Locked 205 XP

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

0 of 5 steps

Project Locked 410 XP

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

0 of 5 steps

4 questions, graded as you go.

Chapter 3

## Race

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

Locked 156 XP

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

0 of 4 steps

Locked 174 XP

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

0 of 4 steps

Project Locked 410 XP

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

0 of 5 steps

4 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### See the line

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

Chapter 2

### Steer

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

Chapter 3

### Race

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

Keep going

## The next course on your track

Build a line-following racer is part of the maker track, a ladder of courses from zero to expert.

Next course

### Build a robot vacuum

Bumpers and cliff sensors, wheel encoders and a map, random bounce against spiral against rows, a five-layer behavior ladder, and a battery that sends it home to its dock.
Open the next course

Track

### Maker track

Follow the starter kit you already own, then build a claw machine, a balance bot, a handheld console or an LED cube, each a short course checked by the simulator.
See every course on the track

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Build a line-following racer

Is Build a line-following racer free?

Yes. All 7 lessons of Build a line-following racer are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Build a line-following racer take?

About 6 hours: 7 lessons in 3 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Line position, P then PD and Project: a race track.

Where do I start?

With "Sensor arrays", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
