Week 1 ยท Getting Started

Session 3: Variables and Serial output

Teach & build120 minLesson 04: Sketch Structure, Variables & Types

Learning outcomes

  • Declare, assign and print variables with Serial.print and Serial.println
  • Use const for pin numbers and fixed values
  • Explain global and local scope in a sketch
  • Predict a sketch's Serial output before running it

Kit and components

  • Uno, USB cable and lab PC
  • Serial Monitor at 9600 baud

Pre-reading about 20 min

Students read these on their phones before class. They are listed on the student Before class page.

  1. Lesson 04: setup once, loop forever
  2. Lesson 04: Variables store changing values
  3. Lesson 04: const for pins and fixed values
  4. Theory Reference: Serial.begin() and Serial.println()

Session plan

  1. 0:0010 min
    Recap

    Quiz: setup, loop and upload

  2. 0:1025 min
    Demo

    Variables change, constants do not

    Live-code a counter printed from loop(). Students predict each line before you run it. Then move the declaration inside loop() and show the counter reset every pass.

  3. 0:3525 min
    Build

    Worked sketch on the board

    Students upload the lesson's worked sketch, change one constant and one variable, and record the new Serial output in the logbook.

  4. 1:0045 min
  5. 1:4515 min
    Wrap-up

    Predict the output

    Project a six-line sketch. Students write its Serial output on paper before you run it.

Checkpoint: ready to move on?

Students can declare an int and a const, print a labelled value on one line, and explain why a variable declared inside loop() resets every pass.

Extension for fast finishers

Catch-up path

Repeat the first variables exercise with the hints open, concentrating on print versus println.

Homework and practice

Code Along 2.3 and 2.4.

Facilitator notes

  • Beginners mistype more than they misunderstand. Let the compiler messages teach and avoid fixing code for students.
  • Code Along compares Serial output exactly - capital letters and spaces matter.