Source: https://mokxi.com/learn/path/safety-critical-software
Updated: 2026-11-20

All paths

# Software that must not fail

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.

Arduino Uno R3 Free 7 lessons 5 h 4 chapters 4,010 XP Coding · Expert +400 XP

0 of 7 done

Start the course free Failure modes Lesson plan for teachers

What you will build

## 3 projects, built step by step

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

Chapter 1 project

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

Chapter 2 project

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

Chapter 3 project

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

## Think in failures

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

Open 400 XP

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

0 of 7 steps

Start What is in it

Project Locked 860 XP

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

0 of 7 steps

4 questions, graded as you go.

Chapter 2

## Catch it while it runs

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

Locked 400 XP

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

0 of 7 steps

Project Locked 800 XP

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

0 of 7 steps

5 questions, graded as you go.

Chapter 3

## Trust nothing once

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

Locked 400 XP

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

0 of 7 steps

Project Locked 700 XP

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

0 of 6 steps

4 questions, graded as you go.

Chapter 4

## Boss

One controller with every layer, attacked until it gives.

Locked 450 XP

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

0 of 8 steps

3 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

### Think in failures

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

Chapter 2

### Catch it while it runs

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

Chapter 3

### Trust nothing once

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

Chapter 4

### Boss

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

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 Software that must not fail

Is Software that must not fail free?

Yes. All 7 lessons of Software that must not fail 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 Software that must not fail take?

About 5 hours: 7 lessons in 4 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: Defensive code, Asserts in production and Reviews.

Where do I start?

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