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

Microbit Seismic and Meteorological Station

In this step-by-step lesson, you'll programme four Microbits to create a Seismic and Meteorological Station. Each Microbit will monitor and display different data: temperature, light levels, and simulated seismic activity. You'll then test your station, and explore ways to enhance it, such as recording historical data or setting specific alert conditions.
Learning Goals Learning Outcomes Teacher Notes Lesson Files

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 - Introduction

    In this project, you will be programming four separate Microbits. Each Microbit will have a unique role in our Seismic and Meteorological Station:

    • Microbit 1: This is the central 'Seismic and Meteorological Station' Microbit. It will use its sensors to monitor temperature, light levels, and 'seismic' activity (which we simulate by shaking the Microbit). It will then broadcast this sensor data wirelessly to the other three Microbits.
    • Microbit 2: This is the 'Temperature Display' Microbit will receive and display the temperature data from Microbit 1.
    • Microbit 3: This is the 'Day/Night Indicator' Microbit will receive the light level data from Microbit 1 and display an indication of whether it's day (high light level) or night (low light level).
    • Microbit 4: This is the 'Seismic Alert' Microbit will receive the 'seismic' activity data from Microbit 1 and display an alert if the Microbit 1 is shaken (simulating a seismic event).

    Now, let's start by creating the first project on MakeCode for Microbit. Go to https://makecode.microbit.org/ and click on 'New Project' and name the project 'Seismic Station'.

    2 - Coding the Seismic Station Microbit

    Let's start with the 'Seismic and Meteorological Station' Microbit. This Microbit will gather and broadcast the sensor data. It will monitor temperature, light levels, and 'seismic' activity (which we simulate by shaking the Microbit).

    Add the following code:

    radio.setGroup(1)
    
    basic.forever(function () {
        radio.sendValue("temperature", input.temperature())
        radio.sendValue("lightlevel", input.lightLevel())
    })
    
    input.onGesture(Gesture.Shake, function () {
    	radio.sendValue("seismicactivity", 1)
    })
    
    

    In the code above, we're setting up the radio communication in group 1. We're also setting up an event handler for the 'shake' gesture to send a 'seismicactivity' message. In the forever loop, the Microbit constantly sends the temperature and light level values.

    Once you have added the code, download it onto the Microbit that will act as the 'Seismic and Meteorological Station'.

    3 - Coding the Temperature Display Microbit

    Next create a new Microbit project and call it something like 'Temperature Display'. This will be the project for the 'Temperature Display' Microbit. This Microbit will listen for the 'temperature' radio messages and display the received value on its LED matrix.

    Add the following code:

    {radio.setGroup(1)
    radio.onReceivedValue(function (name, value) {
        if (name == "temperature") {
            basic.showNumber(value)
        }
    })}

    In the code above, we're setting up the radio communication in group 1 and listening for 'temperature' messages. When such a message is received, the Microbit displays the temperature value.

    Once you have added the code, download it onto the Microbit that will act as the 'Temperature Display'.

    4 - Coding the Day/Night Indicator Microbit

    Now let's create a new Microbit project and call it something like 'Day Night Indicator'. This Microbit will listen for the 'lightlevel' radio messages and display a sun for high light levels (day) and a moon for low light levels (night).

    Add the following code:

    {radio.setGroup(1)
    radio.onReceivedValue(function (name, value) {
        if (name == "lightlevel") {
            if (value > 128) {
                basic.showIcon(IconNames.SmallDiamond)
            } else {
                basic.showIcon(IconNames.SmallSquare)
            }
        }
    })}

    In the code above, we're setting up the radio communication in group 1 and listening for 'lightlevel' messages. When such a message is received, the Microbit checks if the light level is above 128 (this threshold is arbitrary and can be adjusted). If the light level is high, it displays a sun; if it's low, it displays a moon.

    Once you have added the code, download it onto the Microbit that will act as the 'Day/Night Indicator'.

    5 - Coding the Seismic Alert Microbit

    Finally, let's code the 'Seismic Alert' Microbit, create a new project and call it something like 'Seismic Alert'. This Microbit will listen for the 'seismicactivity' radio messages and display and sound a warning if the station detects seismic activity.

    Add the following code:

    radio.onReceivedValue(function (name, value) {
        if (name == "seismicactivity") {
            if (value == 1) {
                basic.showIcon(IconNames.Chessboard)
                music.ringTone(262)
            } else {
                basic.clearScreen()
                music.stopAllSounds()
            }
        }
    })
    radio.setGroup(1)
    

    In the code above, we're setting up the radio communication in group 1 and listening for 'seismicactivity' messages. When such a message is received, the Microbit checks if the value is 1 (which means the onshake triggered to send the message). If seismic activity is detected, it displays and sounds a warning; if not, it clears the screen and stop the sound.

    Once you have added the code, download it onto the Microbit that will act as the 'Seismic Alert'.

    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