Week 2 · Decisions & Debugging

Session 8: Serial commands and debugging

Teach & build120 minLesson 06: UART Serial & Debugging

Learning outcomes

  • Explain UART framing and why both ends need the same baud rate
  • Read single-character commands with Serial.available() and Serial.read()
  • Use temporary Serial traces to locate a logic fault
  • Capture a transmitted character on the oscilloscope

Kit and components

  • Uno, USB cable and lab PC
  • Oscilloscope

Pre-reading about 25 min

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

  1. Lesson 06: UART and baud rate
  2. Lesson 06: Receiving commands
  3. Lesson 06: Debugging strategy
  4. Theory Reference: Serial.available() and Serial.read()

Session plan

  1. 0:0010 min
    Recap

    Quiz: switch and truth tables

  2. 0:1025 min
    Demo

    Commands and the wire

    Send 1 and 0 from the Serial Monitor to switch the LED. Put the scope on TX (D1), trigger on a falling edge at 1 ms/div and capture one character: start bit, eight data bits, stop bit, about 104 µs per bit at 9600 baud.

  3. 0:3535 min
    Build

    Worked sketch plus your own command

    Students upload the worked sketch, then add a command of their own - for example b to blink five times - using a switch on the received character.

  4. 1:1035 min
    Build

    Trace the planted fault

    Give pairs a sketch with a hidden logic fault in a mode chain. They add Serial traces, find the fault and log the symptom, the trace output and the fix.

  5. 1:4515 min
    Wrap-up

    Debugging steps

    Students list the steps they followed; compare with the lesson's debugging strategy.

Checkpoint: ready to move on?

Students can control an output from the Serial Monitor and describe the steps they used to find the planted fault.

Extension for fast finishers

Add a help command that prints the menu, and one that reports the uptime.

Catch-up path

Keep the worked sketch unchanged and add a single command; practise reading the trace output.

Homework and practice

Pre-reading for S9, and Code Along 3.6 if not done.

Facilitator notes

  • On some PCs the Serial Monitor must be closed before uploading.
  • Probe D1 (TX), not D0, for the clearest UART capture.