An optional lesson. Students port the plant-water alarm from Arduino C++ to MicroPython on a Raspberry Pi Pico, matching line to line, converting the threshold (0–1023 to 0–65535) and the timing (milliseconds to seconds), ordering the Python, and running it in Wokwi or on a real Pico.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
SlidesDownload Present from the browser, or export to PowerPoint or PDF.
WorksheetDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can match Arduino C++ to MicroPython line by line.
I can convert a threshold and a timing between the two.
Timing
Predict 3 min · Worked example 12 min · Order 5 min · Wokwi or Pico 10 min · Practise and Make 5 min
Before class
For schools with Picos: Wokwi simulates the Pico in the browser (check its account and embedding terms); Thonny uploads to a real Pico over USB. The Raspberry Pi Foundation's Introduction to Raspberry Pi Pico path is the follow-on.
Simplification: the Pico's ADC is 12-bit, and read_u16 scales it to 16 bits (0–65535).
Running the lesson
Predict: ask what 300 means as a fraction.
Match: point out that Python has no ; and uses indentation instead of { }.
The hard part (on purpose)
Students expect the numbers to carry over. Make the two conversions explicit, on the board, before they run anything.
When students get stuck
What you will see
A question to ask
The fix
The alarm never blinks.
What range does read_u16 give?
Convert the threshold.
The LED stays on for minutes.
What unit does time.sleep take?
Seconds.
Answers to the checks
the threshold: On the Arduino, the alarm blinks at 300 or below (out of 1023). Can the Pico sketch keep the number 300? No. The Pico's read_u16 gives 0 to 65535. 300 out of 1023 is about 29%, which is about 19200 out of 65535.
Match the lines: Match each Arduino line to the MicroPython line that does the same job. pinMode(15, OUTPUT); → A. led = Pin(15, Pin.OUT); digitalWrite(15, HIGH); → E. led.value(1); level = analogRead(A0); → C. level = sensor.read_u16(); delay(250); → B. time.sleep(0.25); void loop() { … } → D. while True: The same five ideas: set up a pin, switch it, read a sensor, wait, repeat for ever.
Two numbers that change: The Arduino threshold is 300 out of 1023. What is that out of 65535? (nearest hundred) 19200 300 ÷ 1023 ≈ 0.293, and 0.293 × 65535 ≈ 19200.
Find the mistake: Sam's Pico port never blinks, and when Sam taps the sensor it stays on for minutes. Click the first line that goes wrong. line 6 Line 6: 300 is the Arduino's scale. read_u16 gives 0 to 65535, so it should be about 19200. (Line 8 has the other copied number: time.sleep(250) waits 250 seconds.)
Vary: put it together: Put the Pico alarm in order. see the program below Imports, then set up the pins, then while True: read, decide, act.
from machine import Pin, ADC
import time
led = Pin(15, Pin.OUT)
sensor = ADC(26)
whileTrue:
level = sensor.read_u16()
if level <= 19200:
led.value(1)
time.sleep(0.25)
led.value(0)
time.sleep(0.25)
else:
led.value(0)
time.sleep(0.1)
Timing: delay(1500) on the Arduino. What goes in time.sleep( ) on the Pico? 1.5 1500 ms = 1.5 s.
What stayed: Which part of the alarm needed no change at all? The idea: read, compare with a threshold, blink or stay off The design transfers; the language and its numbers change.
port the fridge alarm: The fridge alarm's thresholds were 400 and 700 (out of 1023). What is 700 on the Pico's scale? (nearest hundred) 44800 700 ÷ 1023 ≈ 0.684, and 0.684 × 65535 ≈ 44800. (400 becomes about 25600.)
Stretch and support
Stretch: Port the PWM brightness lesson: PWM(Pin(15)) and duty_u16(0 to 65535).
Support: A two-column card: Arduino and MicroPython, with the two number changes boxed.
Exit ticket
Name the two numbers that must change when you port the alarm to the Pico, and how.
The threshold (scale from 0–1023 to 0–65535, × about 64) and the delays (milliseconds to seconds, ÷ 1000).
What each step is for
the threshold: Committing to whether 300 still works as the threshold tests the new move: the idea transfers, but the numbers have to be converted.
Worked example: line for line: Matching each Arduino line to its MicroPython line models the move (the same idea in new words); the two number changes are worked through explicitly. Sam's port, with both numbers copied straight across, is planted after the method.
Vary: put it together: Ordering the MicroPython lines checks the structure transfers: imports and set-up first, then the loop with its decision.
Try it in Wokwi or on a Pico: Running the port on a simulated or real Pico confirms the converted numbers.
converting: Converting timings and readings both ways.
port the fridge alarm: Converting a three-band brief's thresholds to the Pico's scale applies both number changes to a new design.
Where it leads
Next: Power and motors (Years 9–10).
Code: the Python pathway uses the same if, while and indentation.