Lesson plan

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.

4 chapters, 8 lessons, about 7 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

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.

Chapter 1. About 1 h 35 min

Talk and count

Print over serial, and the boxes numbers live in.

LessonTimeWhat 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
  1. Run it: hello, world
  2. print and println
  3. A char is a number
  4. A line with holes in it
  5. Say hello your way
  6. Make it tick faster
  7. Quick check: predict, then run
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
  1. Run it: an int is 2 bytes
  2. long, and why pointers matter
  3. Say the size: stdint.h
  4. Letters are codes
  5. Pick a bigger box
  6. Quick check: predict, then run

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

Chapter 2. About 1 h 50 min

Do the math, pick a path

Operators and what overflow does, then if and switch.

LessonTimeWhat 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
  1. Run it: 7 / 2 is 3
  2. Division and remainder, working together
  3. A uint8_t wraps around
  4. An int overflows
  5. Fix it with a wider type
  6. Bitwise: one bit at a time
  7. Quick check: predict, then run
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
  1. Run it: type r
  2. default catches the rest
  3. The bug: yellow lights green
  4. Add the break
  5. Fall-through on purpose
  6. An else-if ladder
  7. if on a pin
  8. Quick check: predict, then run

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

Chapter 3. About 1 h 40 min

Again, and by name

Loops, then functions, pointers and scope.

LessonTimeWhat 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
  1. Run it: count to ten
  2. while: until the test fails
  3. continue and break
  4. A loop inside a loop
  5. Wait for a button
  6. Change the table
  7. Quick check: predict, then run
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
  1. Run it: square(12)
  2. Prototypes: the promise first
  3. A copy goes nowhere
  4. A pointer reaches the original
  5. static remembers
  6. Why power returns a long
  7. Quick check: predict, then run

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

Chapter 4. About 1 h 50 min

Data and a project

Arrays and C strings, then a quiz built from everything.

LessonTimeWhat 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
  1. Run it: five readings
  2. C does not know how long it is
  3. A string is chars and a zero
  4. Type a word
  5. Compare strings, by hand
  6. Add a reading
  7. Quick check: predict, then run
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
  1. Run it: the first question
  2. Answer right
  3. Answer wrong
  4. Finish and score
  5. Start again with the button
  6. Add a question
  7. Raise the bar
  8. Make it yours

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

Your class

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.