Source: https://mokxi.com/teachers/plans/embedded-c-discipline
Updated: 2026-11-19

Lesson plan

# Embedded C that survives lesson plan

The rules that keep C alive on a chip with 2 KB of RAM, each one broken on the Uno first: 16-bit int overflow, a missing volatile on an interrupt flag, F() and PROGMEM saving SRAM, out-of-bounds writes and signed shifts, String running the heap dry, MISRA-style rules, and a satellite sketch to audit.

3 chapters, 7 lessons, about 6 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 an int really is, what volatile does, and where const data lives.
- Undefined behavior, the heap, and rules a tool can check.
- Audit a satellite telemetry sketch with three hidden bugs.

### Materials for the whole unit

- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Pushbutton
- Resistor

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 25 min

## Data on a small chip

What an int really is, what volatile does, and where const data lives.

Lesson | Time | What students do

Fixed-width types An int is 16 bits on an Uno: five minutes in milliseconds comes out negative, a uint8_t counter wraps to 4, and a millis() interval stays right across the 49-day wrap. Fixed-width types say what you mean. | 55 min

- Run it: how big is an int?
- Five minutes, in milliseconds
- Unsigned types wrap, on purpose
- The millis() wrap
- Fix the overflow
- The habit

volatile The button’s interrupt runs, toggles the lamp and sets a flag, and loop() never sees it, because the optimizer kept the flag in a register. One keyword fixes it, and noInterrupts() makes a 4-byte read safe. | 45 min

- Run it: wait for a press
- Press the button
- What the optimizer did
- One keyword
- volatile is not enough

const and flash The Uno has 32 KB of flash and only 2 KB of SRAM, and every string literal is copied into SRAM at boot. A sine table in PROGMEM costs nothing, and F() on one help text gives back 308 bytes. | 45 min

- Run it: a ground station help text
- A table in flash
- Where the bytes go
- F() the help text
- const everything

### Materials

- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Pushbutton
- Resistor

### Check for understanding

Each student finishes "const and flash" 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: "const everything".

Chapter 2. About 2 h 25 min

## Code that cannot surprise you

Undefined behavior, the heap, and rules a tool can check.

Lesson | Time | What students do

Undefined behavior A loop that runs one step too far writes the knob reading over the alarm limit next door, so the alarm can never fire; a shift into the sign bit goes negative. Both compile cleanly; both are undefined behavior. | 45 min

- Run it: the alarm limit moves
- An alarm that cannot fire
- A shift into the sign bit
- Fix the loop
- What undefined means

Static allocation A telemetry log built with String eats the heap line by line until concat() fails at line 120; the same log in a fixed buffer, sized at compile time, runs for ever with the same largest free block. | 45 min

- Run it: a log in a String
- Watch the heap
- Out of memory
- Why firmware avoids the heap
- A fixed buffer

Coding standards A heater’s command parser written to MISRA-style rules: fixed-width types, named limits, every input range-checked, a static_assert, no heap, and a switch whose impossible case finally says something. | 55 min

- Run it: a parser written to rules
- A valid command
- A value out of range
- The tools enforce the rules
- The case that cannot happen
- Your house rules

### Materials

- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Pushbutton
- Resistor

### Check for understanding

Each student finishes "Coding standards" 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 house rules".

Chapter 3. About 1 h 5 min

## Boss project

Audit a satellite telemetry sketch with three hidden bugs.

Lesson | Time | What students do

Boss: audit the satellite A CubeSat telemetry sketch that compiles without a warning and has three bugs: a mission clock that overflows, a ground station call that loop() never sees, and a checksum written one byte past its buffer into the battery reading. Find each one, then fix it. | 65 min

- Run it: the review begins
- Fix the mission clock
- The ground station calls
- Fix the missed pass
- Where 162 percent comes from
- Fix the packet
- Write up the review

### Materials

- Arduino Uno R3
- Full-size breadboard
- LED
- Pushbutton
- Resistor

### Check for understanding

Each student finishes "Boss: audit the satellite" 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: "Write up the review".

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.
