Microbit
Intermediate
50 mins
Teacher/Student led
+55 XP

Micro:bit Responds to an Input

Pupils program a micro:bit to respond to a sensor input by building a clap-controlled light, then test, debug and suggest one improvement to how their device reacts.

Teacher Class Feed

Load previous activity

    1 - What We're Building ~5 mins

    Illustration for What we're buildingPeople 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.

    2 - Create a New Project ~2 mins

    Go to the makecode.microbit.org website and create a new project.

    3 - Create a Variable ~6 mins

    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

    4 - Sound Threshold ~6 mins

    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)

    5 - Detect a Clap ~3 mins

    Now to detect the clap we will use the on [loud] sound block.

    Add the following code.

    input.onSound(DetectedSound.Loud, function () {
    	
    })
    Pupil practice · Investigation Journal
    Module 4 · Technology: IPO, Algorithms, Makecode Arcade and Micro:bit
    Lesson 28 · Micro:bit Responds to an Input
    123learn · Online learning platform

    Unlock the full learning experience

    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.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more