Microbit
Advanced
50 mins
Teacher/Student led
+55 XP

Data with a Micro:bit

Pupils program a micro:bit to read its built-in sensors, then gather and interpret a small set of readings to spot a simple pattern in real data.

Teacher Class Feed

Load previous activity

    1 - What We're Building ~5 mins

    Illustration for What we're buildingProgrammers and technologists build tools that sense the world and turn what they sense into data — think of weather apps, fitness trackers or the sensors in a smart thermostat. Today you become that kind of technologist. You'll code a micro:bit into a mini weather station that can read the temperature, the light level, the sound and even movement.

    Watch the board first as we build each piece together, then try it on your own device and run it to see what your sensors pick up. By the end you'll gather a few real readings and figure out what they tell you.

    2 - Create a New Project ~3 mins

    Start by creating a new project. Navigate to MakeCode for Microbit and click on 'New Project'. Give your project a name, such as 'Weather Station'.

    3 - Initialize Variables ~8 mins

    First, we need to declare and initialize our two main variables: 'mode' and 'reading'. 'Mode' will help us determine which sensor's data we want to display, and 'reading' will store the sensor data. Add the following code:

    let reading = 0
    let mode = 0
    mode = 1

    The following are the different modes we will have:

    1. is for displaying the temperature.
    2. is for displaying the light level.
    3. is for displaying the sound level.
    4. is for displaying movement.

    4 - Configure Button a ~3 mins

    Let's start by configuring Button A. When this button is pressed, we want 'mode' to be 1. Add the following code:

    input.onButtonPressed(Button.A, function () {
       mode = 1
    })

    5 - Configure Button B ~3 mins

    Next, let's configure Button B. When this button is pressed, we want 'mode' to be 2. Add the following code:

    input.onButtonPressed(Button.B, function () {
        mode = 2
    })
    Pupil practice · Investigation Journal
    Module 4 · Technology: a Coding Build, Micro:bit Data and Presenting Data
    Lesson 26 · Data with a Micro:bit
    Download Investigation Journal sheet (PDF)
    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