Week 2 · Lesson 2 · 55 minutes
Test repeated and invalid commands
I can explain what changes the LED state and test commands that should leave it unchanged.
Planned lesson. Follow your teacher’s teaching order.
Task steps and checks
Find which input changes the state
- Recheck 1 and 0 first. Send the pairs on page 2 separately, pausing after each character. Then select Both NL & CR and send 1 and 0 separately.
- Compare the light before and after the second input. Keep the monitor result separate. Reset or re-upload only as a separate check.
- Command arrives
- 1 or 0 sets state
- Other input leaves it alone
Check your result: If 1 has turned the LED on, then x should leave it on. A reset is different: the starter begins with the LED off.
Revised weekly handout pages: 2.
Materials
Working ESP32 and LED circuit with its existing series resistor, USB data cable, computer and Arduino IDE Serial Monitor. No physical button is needed. · One individual weekly handout; hardware may be shared in pairs.
Resources
Vocabulary
- serial input
- characters sent from the computer to the ESP32 over the serial connection
- state
- the current stored value, such as LED on or off
Original classroom model
Commands that keep the same state
Check 1 and 0 before these tests. No button, new wiring or reaction-timer measurement is needed.
Use the buttons to step through. With scripts off, every frame remains readable.
Repeated command
- LED on
- Send 1 again
- Still on
Sending 1 sets on; it does not toggle the state. Compare this prediction with the real result.
Read the diagram
- LED on
- Send 1 again
- Still on
Invalid command
- LED on
- Send x
- Still on
An invalid character leaves the stored state unchanged and prints a reminder. CR and LF line endings are silently ignored.
Read the diagram
- LED on
- Send x
- Still on
If the LED is on, what should x do?
Discuss before revealing
It should print a reminder and leave the LED on. A board reset is different: this sketch starts with LED off.
See it
More examples and practice
Reopen your own evidence · 5 minutes
Open the saved SerialLED sketch and page 1. Check 1 and 0 first. If they are not reliable yet, continue that work and record the fault; do not invent results for later tests.
Predict what stays the same · 10 minutes
The program compares the received character with '1' and '0'. Sending 1 again keeps the LED on; it does not toggle it. Sending 0 again keeps it off.
An invalid character such as x prints a reminder and leaves the stored LED state unchanged. Carriage return and newline are ignored without changing the state. These are serial characters, not electrical HIGH and LOW input readings.
Predict 1 → x → 0 → x. What should happen to the LED after each command?
Reveal reasoning
On → still on → off → still off. Only 1 and 0 change the stored state. Each x produces an invalid-command message. These are predictions; record your own observed results separately.
Run the command checks · 20 minutes
Send one command at a time and pause to observe. On page 2, test: 1 then 1; 1 then x; 0 then 0; 0 then x. Record the predicted state after the second command, actual LED state and feedback. Repeat an unclear test.
For a line-ending check, set Both NL & CR and send 1, then 0. The extra line endings should produce no invalid-command messages. Record what you actually see. Return to No line ending if that is easier.
Keep the existing checked circuit. Unplug USB before any wiring change and retain the series resistor. A reset or re-upload restarts this sketch with LED off; that is different from an invalid command.
Explain one condition and one check · 15 minutes
Point to Serial.available(), Serial.read() and one command comparison in the sketch. Explain the path: typed character → comparison → stored state → LED output. Include the difference between predicted and observed results.
Record one real fault, check and result, or a useful next check. Each student records their own contribution.
Optional only if ready: save a separate copy and change 1/0 to a/b in the comparisons and printed instructions. Predict and retest a, b and an invalid character. Keep the original version. This is not extra homework.
Keep one weekly record · 5 minutes
Save the program and complete the same two-page record. Homework is only unfinished writing from class. Mark tests that did not run NOT TESTED. Physical button work and reaction timing remain future work.
Week 2 · Serial input and LED control
Do only the parts you did not finish in class. Write what really happened; if you did not test something, write NOT TESTED. This is one task for the week, and nothing else is due.
- Page 1: finish your record of the 1 and 0 commands.
- Page 2: finish your record of the repeated and invalid commands.
- Check that you wrote your saved sketch name, what you predicted and what you saw.
- Write one fault with its check and fix, or one next check.
You are finished when: Both pages are complete with your own predictions and real observations.
Why this matters: Your reaction timer needs reliable input and a stored state. This week you show both work.
- You may share hardware, but write your own predictions, observations and contribution.
- Buttons are not available yet, so Serial Monitor is the input this week. Button wiring, reaction timing and false-start tests come later. Keep your completed timer design.
- Hardware stays at school.
Revised weekly handout pages: 1, 2.
Serial input and LED weekly feedback guide
Task-specific feedback guide, not official IB descriptors or an automatic criterion grade.
- Safe practical work
- The actual LED GPIO and on/off levels are checked, the existing resistor is retained, and power is off for any wiring change.
- Input and output evidence
- Predicted and observed results are distinct for 1, 0, repeated and invalid commands. Missing tests are marked NOT TESTED.
- Explanation and contribution
- The student explains how the program matches a command, saves code and records a useful check and their own contribution.
| Band | Observable evidence |
|---|---|
| 0 | No usable record is available yet. |
| 1–2 | Some parts or results are named, but the record is incomplete or predictions are confused with observations. |
| 3–4 | Most required tests and the saved filename are recorded. The input/output explanation or next check needs more detail. |
| 5–6 | Safe checks, saved code and a clear predicted/observed test record are present. The 1/0 rule and the student’s contribution are explained. |
| 7–8 | The record is precise and repeatable, including repeated and invalid commands and a reasoned fault check or improvement. Untested work is honestly identified. |