Learning objective

  • To create a real-world program using a sensor, input and a conditional statement.

Success criteria

  • I can use the temperature sensor input on a micro:bit.
  • I can use a conditional statement to make the micro:bit react to the reading.
  • I can test my program on a physical device.

National curriculum

Computing

Pupils should be taught to:

  • Design, write and debug programs that accomplish specific goals; solve problems by decomposing them into smaller parts.
  • Use sequence, selection, and repetition in programs; work with variables and various forms of input and output.
  • Use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs.

See National curriculum - Computing - Key stages 1 and 2.

Before the lesson

In collaboration with The Micro:bit Educational Foundation.

Watch
Watch
Watch
Watch
Watch
Watch
Watch
Watch
Download: Storm the scoreboard .hex file (pre-loaded onto at least one micro:bit - see Teacher knowledge).
Download: Weather checker .hex file (optional - see Adaptive teaching).
Activity: Weather checker (one between two).

Lesson plan

1: Recap and recall

Explain that the children should recall what they remember about programming using MakeCode.

Display the Presentation: Speak like an expert and arrange the children into pairs. Allow time for them to share their ideas using key vocabulary.

Presentation: Speak like an expert

Take feedback, highlighting any accurate use of subject-specific terms.

The children may share that:

  • The code is for a pedometer, which counts how often the micro:bit is shaken.
  • The ‘on shake’ input block detects movement and triggers the code.
  • The variable ‘steps’ stores and updates the number of steps taken.
  • A conditional statement (an ‘if’ block) checks if the step count has reached a specific number (e.g twenty).
  • When the condition is met, the micro:bit reacts with a celebration, such as showing an icon (e.g a smiley face) or playing a sound.

2: Attention grabber

Hand out the micro:bits with the pre-loaded scoreboard program (see Teacher knowledge) and arrange the children into pairs. Alternatively, load the program onto one micro:bit and complete the quiz as a whole class, inviting volunteers to take turns.

Display the Quiz: Storm the scoreboard and explain that the children will take part in a weather quiz and the micro:bit has been programmed to function as a scoreboard. Assign one child in each pair to be Player A and the other Player B.

Quiz: Storm the scoreboard

Display the quiz questions one at a time. After each question, click to reveal the correct answer. If a player is correct, they press their assigned button to log the score (button A for Player A and button B for Player B). The first player to reach five correct answers wins.

Ask the children:

  • How do you think the micro:bit knows who has more points? (Variables keep track of the scores; button A and B add points for each player.)
  • What do you think the code looks like? (Answers may include: variables; inputs; conditional statements.)

Display the Presentation: Scoreboard code explained.

Presentation: Scoreboard code explained


Make presentation full-screen

Click to reveal and discuss the function of each block:

  • Two variables track each player’s score.
  • Pressing button A increases Player A’s score and pressing button B increases Player B’s score.
  • An ‘if condition’ displays a message when either player reaches five points.
  • Pressing both buttons together resets both scores to zero.

3: Main event

Ask the children:

  • How can we make the micro:bit tell us if it is a good day for PE outside?

Explain that the children will use the micro:bit’s built-in temperature sensor to create a weather checker. The device will respond based on the temperature, using a conditional statement to decide what happens when certain conditions are met.

Play the Pupil video: Programming a weather checker.

Pupil video: Programming a weather checker

Explain that the children will decide what they think is a suitable temperature for PE. The example in the video uses 10°C and below as the threshold but they can set their own.

Note: the temperature may need to be adjusted depending on the season.

Ask the children:

  • What input tells the micro:bit to start checking the temperature in this program? (Pressing button A.)
  • Why do we use a conditional statement in the weather checker program? (To check if the temperature is 10 degrees or below and show the correct icon.)
  • What icon will the micro:bit show if the temperature is over 10 degrees? (A happy face icon.)
  • Why does this program not need a variable to store the temperature? (The sensor gives the reading directly and the program uses it straightaway.)

Hand out the Activity: Weather checker (one between two). Explain that the children need to plan the parts of their program before coding. Display a completed example of the planning sheet on the board to show how each section should be filled in (see Teacher knowledge).

Image: Weather checker sheet example

Hand out the devices (one per pair) and ask the children to open the link: Microsoft MakeCode and open a new project. Allow time to complete and test the program. Ensure each program is downloaded onto a micro:bit once finished (see the Pupil video: Pairing the micro:bit (laptop and desktop version) and Pupil video: Pairing the micro:bit (tablet version)).

4: Wrapping up

Take the children to the hall or playground in pairs, each with their micro:bit, whiteboard and a pen. Explain that they will test their programs by collecting temperature readings in different areas.

Ask the children to walk to locations such as a window, door, bench or piece of outdoor equipment. Explain that they will press button A (or their chosen input) to check the temperature (displayed on the LED grid) and record it on their whiteboard.

Join two pairs together once they have collected readings. Ask each group to report back like weather forecasters, using phrases such as:

  • Over by the bench, it is 22 °C.
  • By the maths display, it is 18 °C.

Ask the children:

  • Why did different places give different results? (Answers may include: the window was warmer from sunlight; the door was colder from airflow.)
  • How could you change your program so it gives a better reading? (Add a pause before showing the temperature so the sensor can adjust.)
  • Can you think of examples at home where something only happens if a condition is met? (Answers may include: smart thermostats; heating turning on when it is cold; lights turning on when it is dark.)

Adaptive teaching

Pupils needing extra support

Should use the Download: Weather checker .hex file or the link: Microsoft MakeCode - Weather checker and remix the code to personalise it (for example, change the temperature and the icons); could re-watch the Pupil Video: Weather checker during programming to reinforce the purpose and sequence of blocks.

Pupils working at greater depth

Should add a ‘clear screen’ function and explain how this improves the program’s usefulness; should add more than one condition to display different messages depending on the temperature range; could include an additional custom message (for example, ‘Wrap up warm!’ between 5–10 °C or ‘Keep hydrated!’ above 25 °C) – (see Teacher knowledge).

Assessing progress and understanding

Pupils with secure understanding indicated by: using the temperature sensor block and creating a variable to store temperature data; programming a simple conditional statement to trigger a reaction based on the temperature; testing their code on a micro:bit and explaining how the device responds to the temperature reading.

Pupils working at greater depth indicated by: modifying their code to include a clear screen function and explaining how this improve the program’s usefulness; programming multiple conditional statements to trigger different outputs for different temperature ranges.

Vocabulary definitions

  • conditional statement

    A rule in code that makes something happen only if a specific condition is true.

  • input

    An action that gives the micro:bit information, such as pressing a button or shaking it.

  • sensor

    A built-in device that detects information from the environment, such as light, temperature or movement.

Our team comprises experienced classroom teachers who love the foundation subjects
Find out more
Kapow logo

Maintained by: Kapow Primary team

_
For copyright reasons, you may not screenshot this page.
Press esc to exit
close popup

Are you sure you want to download this lesson plan?

Downloading may not be your best option. Be sure you are looking at the most up-to-date version by always viewing your resources online.

Bookmark or save the link to this lesson so you can find it quickly! Do you want to continue?