Lesson 4: Using the temperature sensor
Creating and testing a program that uses the temperature sensor.
New statutory RSHE guidance is here. We’re creating our brand new RSE & PSHE scheme ready for September 2026. Learn more
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.
Before the lesson
Check all images, videos, links and presentation slides are suitable for your class.
- Presentation: Speak like an expert.
- Quiz: Storm the scoreboard.
- Presentation: Scoreboard code explained.
- Image: Weather checker sheet example.
Devices (one between two - see Teacher knowledge).
BBC micro:bits with battery packs if using tablets and micro USB cables if using laptops (one between two).
A large space (such as a hall or playground - see Wrapping up).
Whiteboards and pens (one each).
Link: Microsoft MakeCode.*
Link: Microsoft MakeCode - Storm the scoreboard (pre-loaded onto at least one micro:bit - see Teacher knowledge).*
Link: Microsoft MakeCode - Weather checker (optional - see Adaptive teaching).*
*These are external websites and we do not have control over their content – please check before showing them to the children.
Subject knowledge
Completed example of the Activity: Weather checker:
Adaptive teaching: Greater depth code examples
To clear the screen, children need to add an input (on button press) and use the 'clear screen' block.

To add an extra condition, children can click the plus icon on the 'if block' to include an 'else if'. Instead of using icons, they can use the show string block to display a message. The program is no longer choosing between two outcomes, but checks the temperature step by step to decide the most suitable response.

Lesson organisation
This unit uses a BBC micro:bit, a physical programmable device. BBC micro:bits are available to buy or borrow, often from a local library, if not already available in school.
If physical devices are not available, the virtual micro:bit in Microsoft MakeCode can be used as an alternative.
Programming language
This unit uses MakeCode, a block-based editor similar to Scratch. Although the BBC micro:bit can also be programmed in Python, a text-based language, Python is not used in this unit.
Key setup information
A micro USB cable is required to connect the micro:bit when using laptops.
Battery packs are useful for children who use tablets via Bluetooth to allow them to move around with their devices.
Where both laptops and tablets are available, laptops are recommended as they are generally easier to manage in a classroom setting.
Accessing and saving projects in MakeCode
Microsoft MakeCode does not require a login. Projects save locally in the browser on the device being used. For this reason, the pupils should ideally use the same device each lesson so their projects remain visible in ‘My Projects’. If pupils need to continue work on a different device, model how to download and re-upload a project using a .hex file:
Open the project in MakeCode.
Select Download in the bottom left corner.
Save the .hex file to the device or school platform.
In the next lesson, open MakeCode and select Import (see the grey button, mid-height on the right-hand side of the screen).
Upload the saved .hex file to continue working.
Using tablets
Ensure the BBC micro:bit app is installed.
Connect a battery pack before pairing as the micro:bit needs power.
Numbering tablets and devices can help maintain consistent pairing across lessons. Alternatively, random pairing can be used as children quickly become familiar with the process.
Using laptops or desktops
When connected via USB, the micro:bit draws power directly from the computer. Battery packs are not needed during programming.
Accessing the project
Before the lesson, ensure that the Storm the scoreboard program is pre-loaded onto at least one micro:bit.
The project can be opened in two ways:
Through the project link in Microsoft MakeCode.
By downloading the provided .hex file.
Option 1: Opening the project through the link
Click the links: Microsoft MakeCode -Storm the scoreboard and Microsoft MakeCode -Weather checker to open the projects in MakeCode. Press 'edit' to store a copy in the browser. Logging in is not required. Rename the project to keep edits separate from the original in the text box along the bottom of the screen.
Option 2: Using the .hex file
Download the Download: Storm the scoreboard .hex file and the Download: Weather checker .hex file from the Have ready. Double-click the folder to access the files and then drag and drop them into the MakeCode editor.
This process can also be seen in these videos:
Health and safety
MakeCode offers a sign-in option but a login is not required for pupils. Schools should follow their own policies regarding pupil accounts.
Kapow recommends using MakeCode without signing in as local saving avoids unnecessary data sharing and reduces safeguarding risk.
Projects are saved locally in the browser so the pupils should use the same device each lesson to prevent losing access to their work.
See Teacher knowledge for guidance on downloading and importing projects when different devices are used in lessons.
Lesson plan
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.
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.
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.
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.
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.
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.
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).

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)).
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.)
Full-screen slides, ready for your classroom, chosen by you.
-
To create a real-world program using a sensor, input and a conditional statement.
We value your feedback
We welcome your feedback to help make our resources even better




