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.

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.

LessonTimeWhat 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
  1. Run it
  2. How one sensor sees
  3. Two at once
  4. Five bits, one number
  5. Lost
  6. A bar across
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
  1. A weighted average
  2. The other side
  3. Predict it
  4. Steps, not a slope
  5. 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.

LessonTimeWhat 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
  1. Run it
  2. How fast is full
  3. Spin on the spot
  4. Brake is not coast
  5. Coast
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
  1. Run it
  2. P: steer by the error
  3. Turn it up, and hit the wall
  4. D: steer by the change
  5. 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.

LessonTimeWhat 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
  1. Base speed
  2. Grip is physics
  3. Slow in the bends
  4. A tired pack
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
  1. The start line
  2. One lap
  3. How far is a lap
  4. The best lap
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
  1. Lay out the track
  2. Three laps and the flag
  3. Your gains in the code
  4. A failsafe
  5. 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.