C from zero lesson plan
The language under every microcontroller, from a first hello over serial: types and sizes, overflow, if and switch, loops, functions and pointers, arrays and strings. Ends with a serial quiz you build and make your own.
Objectives and materials
By the end, students can
- Print over serial, and the boxes numbers live in.
- Operators and what overflow does, then if and switch.
- Loops, then functions, pointers and scope.
- Arrays and C strings, then a quiz built from everything.
Materials for the whole unit
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
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.
Talk and count
Print over serial, and the boxes numbers live in.
| Lesson | Time | What students do |
|---|---|---|
| Hello over serialThe first C program on an Uno: setup and loop, print against println, a char that turns out to be a number, and a line built with snprintf every second. | 50 min |
|
| Types and sizesEvery variable is a box with a fixed number of bytes. sizeof on the Uno, the fixed-width types from stdint.h, what each one holds, and a char that is really a number. | 45 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Types and sizes" 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: "Quick check: predict, then run".
Do the math, pick a path
Operators and what overflow does, then if and switch.
| Lesson | Time | What students do |
|---|---|---|
| Operators and overflowInteger division and the remainder, a uint8_t that wraps like an odometer, an int that overflows and why that is undefined, the fix with a wider type, and bitwise operators on three lamps. | 50 min |
|
| if and switchThe program picks one way to go: serial commands chosen with a switch, a fall-through bug to find and fix, an else-if ladder for temperatures, and a button read with if. | 60 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "if and switch" 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: "Quick check: predict, then run".
Again, and by name
Loops, then functions, pointers and scope.
| Lesson | Time | What students do |
|---|---|---|
| LoopsDo it again: for when you know how many times, while when you wait for something, do-while that always runs once, continue and break, a loop inside a loop, and a while that waits for a button. | 50 min |
|
| FunctionsName a piece of work once: prototypes, parameters and return values, why a copy cannot change the caller and a pointer can, a local that hides a global, and a static counter that remembers. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Functions" 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: "Quick check: predict, then run".
Data and a project
Arrays and C strings, then a quiz built from everything.
| Lesson | Time | What students do |
|---|---|---|
| Arrays and stringsMany values in a row: sum and max over an array, its length from sizeof, and text as a char array ending in a zero byte, with strlen and strcmp written by hand and a buffer that never overflows. | 50 min |
|
| Project: a serial quizEverything in the course in one program: questions in an array of structs, answers read from Serial, a switch to check them, a score, lamps for right and wrong, and a button to start again. Then make it yours. | 60 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Project: a serial quiz" 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: "Make it yours".
Teach this unit as a class
Start a class from this course and its 8 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.