← Exit
/ Space navigate · n notes · f fullscreen · Esc exit

Crack the Code · Stage 4

Weeks 3–4 · Inputs, outputs & the PRP activities

Use digital and analog inputs to control outputs. Read a button with `digitalRead`, a potentiometer/LDR with `analogRead`, and drive an LED and a piezo buzzer. Use the Serial Monitor to inspect what your program is doing.

TE4-4DPTE4-7DITE4-DES-01TE4-DIG-02

Open this deck on the projector and press F for full-screen. N toggles speaker notes. The accompanying teacher guide is at /curriculum/crack-the-code/teacher/lessons/3.

Before this lesson:

  • Verify the Serial Monitor opens cleanly on every machine (baud rate 9600).
  • Pre-load the four sample sketches in the IDE: _02_Button, _03_int, _05_analog_input, _07_Buzzer1.
  • Print or share the PRP 2/3/4 student pages; these are the activity guides students follow.
  • Have a working potentiometer-controlled night light to show before students start PRP 3.
intention 2 min

Inputs, outputs & the PRP activities

Use digital and analog inputs to control outputs. Read a button with digitalRead, a potentiometer/LDR with analogRead, and drive an LED and a piezo buzzer. Use the Serial Monitor to inspect what your program is doing.

  • Verify the Serial Monitor opens cleanly on every machine (baud rate 9600).
  • Pre-load the four sample sketches in the IDE: _02_Button, _03_int, _05_analog_input, _07_Buzzer1.
  • Print or share the PRP 2/3/4 student pages; these are the activity guides students follow.
  • Have a working potentiometer-controlled night light to show before students start PRP 3.
task 30 min

Today's work

  • List common items that use each type of sensor and each type of actuator.
  • PRP #02 (Button): IPO chart; load & run the Button sketch; change the button pin to 7; write pseudocode for "LED on when the button is pressed"; "making connections" questions; challenges (reverse the action; LED stays on 3 s after release; turn the button into a toggle switch); evaluation questions.
  • PRP #03 (Analog input): IPO chart; load & run the analog-input sketch; open the Serial Monitor; pseudocode for "blink faster/slower with the pot"; challenges (several LEDs flash; reverse the pot so it speeds up the other way — 1023 − sensorValue; LEDs scroll as you turn the dial; a night light that turns the LED on when the LDR reading is low); evaluation questions.
  • PRP #04 (Buzzer): IPO chart; type up the buzzer sketch; pseudocode to make the buzzer sound; "making connections"; make it sound like an alarm; challenges (two or more tones; buzzer only while the button is pressed; toggle the buzzer; play a familiar tune); evaluation questions.
  • Introduce a range of input components / sensors — switches, motion, light, sound, level, pressure, thermal and mechanical (potentiometer) sensors — and explain each.
  • PRP #02 (Button): demonstrate loading the Button sketch; have students set the button pin to 7 (the ThinkerShield button) and modify the code; revisit the int command in context (intuitive pin names; easy pin changes).
  • PRP #03 (Analog input): demonstrate loading the analog-input sketch (POT on A5); demonstrate the Serial Monitor so students can see the changing value; later have them swap the input to the LDR.
  • Introduce output components / actuators — light, sound, motion — and explain each.
  • PRP #04 (Buzzer): have students type up the buzzer sketch from the workbook; extension — change the tone so it sounds like an alarm.
  • Provide feedback on student achievement after each PRP. Offer extension activities (improve the code; change variables; add a sensor; build a simple car alarm; use the tone command). Optionally screen the VEA Introduction to Programming video.
check 3 min

Quick check

  • I can wire and run PRP 2 (Button), PRP 3 (Analog input) and PRP 4 (Buzzer).
  • I can read a sensor value from the Serial Monitor and use it to decide what an output does (if/else).
  • I can use the int command to give a pin a friendly name in code.
  • I can describe how the alarm project will use one of these inputs + one of these outputs.
  • = vs == — single = assigns; double == compares. The compiler won't always catch this.
  • Wrong pin on ThinkerShield — button is D7, buzzer is D3, pot is A5, LDR is A4. Some printed copies of the workbook have the wrong pin numbers; the sample sketches here are correct.
  • Serial Monitor blank or garbled — baud rate mismatch (must be 9600).
  • analogRead returns 0–1023, not 0–255. The delay(sensorValue) trick visualises this.
reflect 3 min

Before you pack up

Which of the three PRPs felt closest to your alarm idea? What input + output will your alarm use?

  • Three completed IPO charts (PRP 2, PRP 3, PRP 4).
  • Screenshot or video of each student's working button, working analog input + Serial Monitor, working buzzer.
  • Annotated code for at least one PRP showing modifications.
  • Challenge checkboxes signed off for each PRP.

End of lesson 3

That's it.

Tomorrow / next lesson: Generating, developing & testing design ideas.