Software that must not fail lesson plan
Write firmware for a heater the way safety engineers do: failure modes, defensive input, the real watchdog, asserts that stay, redundancy and reviews, all on an Uno.
Objectives and materials
By the end, students can
- What can break, how bad it is, and code that refuses to believe bad input.
- The chip's watchdog for hangs, and asserts that fail safe in the field.
- Two sensors, a setpoint stored twice, and a review that finds three bugs.
- One controller with every layer, attacked until it gives.
Materials for the whole unit
- Arduino Uno R3
- Filament lamp x 2
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 4
- Signal generator
- Solid-state relay, SSR-25DA / G3MB-202P
- Temperature sensor, DS18B20 x 2
- Thermistor, 10k NTC
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.
Think in failures
What can break, how bad it is, and code that refuses to believe bad input.
| Lesson | Time | What students do |
|---|---|---|
| Failure modesA naive thermostat that trusts every reading, and an FMEA table that ranks what can go wrong by severity, occurrence and detection. Break the sensor wire and watch it heat a tank it thinks is colder than space. | 45 min |
|
| Defensive codeThe heater takes its setpoint over serial and trusts none of it: a line buffer that cannot overflow, strtol with an end pointer, a range check before the cast, and a clear REJECTED for everything else. | 45 min |
|
Materials
- Arduino Uno R3
- Filament lamp x 2
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 4
- Signal generator
- Solid-state relay, SSR-25DA / G3MB-202P
- Thermistor, 10k NTC
Check for understanding
Each student finishes "Defensive code" 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: "Predict, then run: the wrap".
Catch it while it runs
The chip's watchdog for hangs, and asserts that fail safe in the field.
| Lesson | Time | What students do |
|---|---|---|
| WatchdogsThe ATmega328P's real watchdog at 250 ms: a hang it catches, a slow job that trips it, the reset cause in MCUSR, and a bad setting that hangs every boot until a counter in EEPROM drops it into safe mode. | 45 min |
|
| Asserts in productionA SAFE_ASSERT macro that never compiles away: on a broken invariant it cuts the heater, records the line number in EEPROM, resets through the watchdog and stays latched until a person presses RESET. | 45 min |
|
Materials
- Arduino Uno R3
- Filament lamp x 2
- Full-size breadboard
- LED x 2
- Pushbutton
- Resistor x 3
- Signal generator
- Solid-state relay, SSR-25DA / G3MB-202P
- Thermistor, 10k NTC
Check for understanding
Each student finishes "Asserts in production" 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: "Assert, handle, or validate?".
Trust nothing once
Two sensors, a setpoint stored twice, and a review that finds three bugs.
| Lesson | Time | What students do |
|---|---|---|
| RedundancyTwo DS18B20s watch one tank and must agree within 2 C, the hotter one wins, and the setpoint is stored twice, once inverted, so a flipped bit in RAM is caught before it is used. | 45 min |
|
| ReviewsA heater controller with three planted bugs, found the way a reviewer finds them: a stray semicolon that trips at room temperature, a 16-bit int that makes the dry-fire cutout impossible, and a wait loop with no way out. | 35 min |
|
Materials
- Arduino Uno R3
- Filament lamp x 2
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
- Signal generator
- Solid-state relay, SSR-25DA / G3MB-202P
- Temperature sensor, DS18B20 x 2
- Thermistor, 10k NTC
Check for understanding
Each student finishes "Reviews" 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: "Your review checklist".
Boss
One controller with every layer, attacked until it gives.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a fail-safe heaterEvery layer in one controller: a sensor plausibility check, a latched over-temperature trip only a person can reset, a guarded setpoint, SAFE_ASSERT and the real watchdog. Attack it, then find the one failure mode it still misses. | 50 min |
|
Materials
- Arduino Uno R3
- Filament lamp x 2
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 4
- Signal generator
- Solid-state relay, SSR-25DA / G3MB-202P
- Thermistor, 10k NTC
Check for understanding
Each student finishes "Boss: a fail-safe heater" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Sign it off".
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.