Lesson plan

Control systems: PID lesson plan

Feedback control on real physics: open and closed loops, P, I and D one at a time, tuning by the numbers, encoders, a balancing robot, and a motor that holds its speed whatever you throw at it.

5 chapters, 7 lessons, about 7 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

  • Why measuring and correcting beats a good guess.
  • Each term on its own: what it fixes and what it breaks.
  • Step tests and Ziegler-Nichols, and the encoder every loop leans on.
  • A balancing robot, where the controller is all that keeps it up.
  • Hold a motor speed through a sag, a surge and a stall.

Materials for the whole unit

  • Arduino Uno R3
  • Bench power supply
  • Gear motor with encoder
  • Half breadboard
  • Motor driver, L9110S
  • OLED display, 128x64
  • Potentiometer x 3
  • Self-balancing robot

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 1 h 10 min

Feedback

Why measuring and correcting beats a good guess.

LessonTimeWhat students do
Open loop, closed loopDrive a gear motor at a fixed PWM and watch the speed drift the moment the supply sags. Then close the loop: measure, compare, correct, and the speed comes back on its own.70 min
  1. Run it: a motor on a guess
  2. Watch it come up to speed
  3. Pull the supply down
  4. Close the loop
  5. Same sag, closed loop
  6. The four numbers
  7. Ask for a different speed

Materials

  • Arduino Uno R3
  • Bench power supply
  • Gear motor with encoder
  • Motor driver, L9110S

Check for understanding

Each student finishes "Open loop, closed loop" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Ask for a different speed".

Chapter 2. About 2 h

P, I and D

Each term on its own: what it fixes and what it breaks.

LessonTimeWhat students do
P, then IProportional control and the offset it always leaves, why cranking the gain makes it hunt instead, the integral term that wipes the offset out, and the windup that bites when the output hits its limit.60 min
  1. Run it: proportional control
  2. The offset P always leaves
  3. Crank it, and it hunts
  4. I: the term with a memory
  5. Windup
  6. Anti-windup
D: dampingA position loop that turns the wheel to an angle: P alone acts as a spring and overshoots, D acts as a damper and stops it clean, friction leaves the last few degrees, and too much D buzzes.60 min
  1. Run it: P on position
  2. A softer spring is no cure
  3. Add D
  4. Too much D
  5. Write the damper in
  6. The last degree

Materials

  • Arduino Uno R3
  • Bench power supply
  • Gear motor with encoder
  • Motor driver, L9110S

Check for understanding

Each student finishes "D: damping" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The last degree".

Chapter 3. About 2 h

Tuning and sensing

Step tests and Ziegler-Nichols, and the encoder every loop leans on.

LessonTimeWhat students do
Tuning by the numbersStep tests that measure rise time, overshoot, settling time and steady-state error, the Ziegler-Nichols experiment for finding the ultimate gain and period, and a tune refined until it meets a written spec.60 min
  1. Run it: a step test
  2. Ziegler and Nichols, part 1
  3. The ultimate gain
  4. Ziegler and Nichols, part 2
  5. Refine it to the spec
  6. Ship the tune
Encoder speedCount a quadrature encoder in interrupts: direction from the phase between A and B, x1, x2 and x4 decoding, speed by counting edges or by timing them, and how the measurement decides how steadily a loop can hold 30 rpm.60 min
  1. Run it: edges in an interrupt
  2. Which way? The quadrature trick
  3. Hold 30 rpm by counting
  4. Time the edges instead
  5. Read it safely
  6. Four times the edges

Materials

  • Arduino Uno R3
  • Bench power supply
  • Gear motor with encoder
  • Motor driver, L9110S

Check for understanding

Each student finishes "Encoder speed" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Four times the edges".

Chapter 4. About 1 h

Unstable plants

A balancing robot, where the controller is all that keeps it up.

LessonTimeWhat students do
Balance controlPID on an unstable plant: the balance bot’s tilt held at zero, each term knocked out to see what it was doing, pushes measured, and a stiffer tune written into the code.60 min
  1. Run it: an unstable plant
  2. Push it
  3. Take D away
  4. Take I away
  5. Stand it back up
  6. A stiffer tune

Materials

  • Arduino Uno R3
  • Half breadboard
  • OLED display, 128x64
  • Potentiometer x 3
  • Self-balancing robot

Check for understanding

Each student finishes "Balance control" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A stiffer tune".

Chapter 5. About 1 h

Boss

Hold a motor speed through a sag, a surge and a stall.

LessonTimeWhat students do
Boss: hold the speedThe final fight: a clean start to 120 rpm, a supply sag, a surge, and a stall no controller can win, refereed round by round by the sketch. Beat all four with your own gains and anti-windup.60 min
  1. Run it: meet the referee
  2. Round 1: the start
  3. Round 2: the sag
  4. Round 3: the surge
  5. Round 4: the stall
  6. Win it in the code

Materials

  • Arduino Uno R3
  • Bench power supply
  • Gear motor with encoder
  • Motor driver, L9110S

Check for understanding

Each student finishes "Boss: hold the speed" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Win it in the code".

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.