Microbit
Beginner
50 mins
Teacher/Student led
+100 XP

Logging Data Over Time with a Micro:bit

Students continue their micro:bit project by reading on-board sensors and turning live data into bar graphs, predicting and testing each change as they build.

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~5 mins

    Quick recap: last day, what does a forever loop let our program keep doing? Today we're back in MakeCode for micro:bit to make our device show live sensor data as a graph on its LEDs. Open the project you saved earlier — we'll predict first, then build, run and fix as a class.

    2 - Predict Before You Run ~10 mins

    Before anyone runs anything: look at what we're about to build. When the program runs, what do you think the micro:bit will show first? What will happen on screen if the light around it changes? Commit to a prediction with your partner before you press run.

    3 - Create a New Project ~5 mins

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

    4 - Show Light Level ~5 mins

    The first sensor that we'll look at is the light level sensor. This senses how much light from the surrounding environment is hitting the front of the Microbit.

    This number can be between 0 (black) and 255 (white).

    Let's display the light level on the Microbit now. 

    basic.forever(function () {
        basic.showNumber(input.lightLevel())
    })
    You can change the amount of light on the Microbit simulator by using the yellow/grey circle in the top left corner (watch the gif for this step).

    Make sure to download the code on to your Microbit to test it out for real by shining more/less light on it!


    5 - Graph Light Level ~5 mins

    We'll now do something a bit more interesting using the light level. We can view the light level on a graph that will illustrate the changes in light.

    basic.forever(function () {
        led.plotBarGraph(
        input.lightLevel(),
        255
        )
    })

    You can view the graph on the simulator on your computer (click the "show data" button under the Microbit). Change the light level on the Microbit simulator and see how the graph changes!

    Then, download the code on to your Microbit.


    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