Microbit Sensors & Circuits Coding Basics
Intermediate
60 mins
Teacher/Student led
125 points
What you need:
Chromebook/Laptop/PC
Microbit

Designing a Microbits Weather Station

Embark on a journey to create your own Microbits Weather Station. You'll start by creating a new project, initialise variables, and configure buttons. You'll learn to detect loud sounds and create a 'forever' loop to display relevant sensor data. Finally, test your program and reflect on your learning.
Learning Goals Learning Outcomes Teacher Notes

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Create a New Project

    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'.

    2 - Initialize Variables

    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.

    3 - Configure Button A

    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
    })

    4 - Configure Button B

    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
    })

    5 - Configure Buttons A and B

    Now, let's configure the combination of Buttons A and B. When both these buttons are pressed, we want 'mode' to be 3. Add the following code:

    input.onButtonPressed(Button.AB, function () {
        mode = 3
    })

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland. 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