People who build technology often make devices that sense the world and react — a security light that comes on when it hears a noise, or a phone that responds when you shake it. Today you're the programmer. You'll turn your micro:bit into a clap-controlled light: clap once and the lights come on, clap again and they go off. First watch the board as each piece is built, then try it on your own device and run it to see what happens. Real programmers rarely get it perfect first time — so testing and fixing bugs is part of the plan.
Set the scene: today pupils become programmers building a device that senses sound and reacts. Model the first step or two on the IWB before pairs work independently, and let them know they'll download to real micro:bits and clap to test. Ask: "What everyday gadgets react to sound or movement?" Reassure them that bugs are expected — finding and fixing them is part of the job.
Go to the makecode.microbit.org website and create a new project.
Go to the Makecode.com Microbit website using the link below and click on the 'New Project' button underneath the 'My Projects' heading.
https://makecode.microbit.org/
Install the micro:bit app on your iPad or tablet.
Open the app, tap 'Create code' and then create a new project.

Show pupils how to open the MakeCode site and start a fresh project on the IWB. Common snag: some pairs may reopen an old project — check each new project is empty. Circulate to confirm everyone reaches the same starting screen before moving on.
In this project we are going to detect when you clap using the microphone in your Microbit. When we detect a clap we will turn on the LED lights of the Microbit or turn them off if they're already on.
To decide whether to turn them on or off we will need a variable to store if they are currently on or off.
Create a variable called lightOn. and then add the following code to set this variable to false at the start.
let lightOn = false
In the Variables toolbox, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
Explain the plan first: the micro:bit will listen for a clap and switch its lights on or off, so it needs to remember the current state. Model creating the variable on the IWB. Key question: "Why do we need to remember whether the light is already on?" Misconception to watch: pupils setting the variable but forgetting to set it to false at the start — check the on-start block.
For detecting the clap, we need to set how loud a sound we need to listen for. To do this we use the set [loud] sound threshold to block.
Add this block into the on start block and set the value to 128 (the range in 0 to 255).
let lightOn = false lightOn = false input.setSoundThreshold(SoundThreshold.Loud, 128)
Model adding the sound-threshold block and explain 128 is roughly the middle of the 0–255 range. Ask: "What might happen if we set this too high or too low?" Note that this value often needs adjusting later for their real room. Support: let pupils copy your board value exactly for now.
Now to detect the clap we will use the on [loud] sound block.
Add the following code.
input.onSound(DetectedSound.Loud, function () {
})
Show where the on-sound block goes and explain it is the trigger — code inside runs only when a loud sound is heard. Bug to watch: pupils placing later blocks outside this block so nothing happens on a clap. Ask: "When does the code inside this block run?"
You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.