Source: https://mokxi.com/teachers/plans/safety-critical-software
Updated: 2026-11-19

Lesson plan

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

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

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

Chapter 1. About 1 h 30 min

## Think in failures

What can break, how bad it is, and code that refuses to believe bad input.

Lesson | Time | What students do

Failure modes A 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

- Run it: a heater that works
- A hot tank
- Break the wire
- Rank what can go wrong
- Lower the RPN: detect it
- Add your own row
- Name the safe state

Defensive code The 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

- Run it: orders over serial
- A good order
- Out of range
- Not a number
- Too long to fit
- Close the gap
- Predict, then run: the wrap

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

Chapter 2. About 1 h 30 min

## Catch it while it runs

The chip's watchdog for hangs, and asserts that fail safe in the field.

Lesson | Time | What students do

Watchdogs The 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

- Run it: a dog on a 250 ms leash
- Hang it
- A slow job trips it too
- Feed it from the work
- A boot loop
- A person clears it
- Quick check: where to feed it

Asserts in production A 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

- Run it: time-proportioning
- Warm tank, small duty
- A cold morning
- The note survives the reset
- A person presses RESET
- Fix the bug, keep the assert
- Assert, handle, or validate?

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

Chapter 3. About 1 h 20 min

## Trust nothing once

Two sensors, a setpoint stored twice, and a review that finds three bugs.

Lesson | Time | What students do

Redundancy Two 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

- Run it: two probes disagree
- Make them agree
- The safe guess
- A flipped bit
- Tighten the limit
- Predict, then run: a hot tank
- When both fail together

Reviews A 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

- Run it: something is wrong
- Bug 1: a semicolon
- Bug 2: watch the clock
- Fix the int
- Bug 3: a loop with no exit
- Your review checklist

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

Chapter 4. About 50 min

## Boss

One controller with every layer, attacked until it gives.

Lesson | Time | What students do

Boss: a fail-safe heater Every 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

- Run it: the whole controller
- Normal service
- Attack 1: overheat
- Only a person resets it
- Attack 2: cut the wire
- Attack 3: hang it
- Attack 4: the one it misses
- Sign it off

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

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.
