micro:bit Tilt Alarm

In this activity, students design a motion-based security system using the micro:bit’s built-in accelerometer and radio features. The program detects when one micro:bit is moved or shaken and responds by displaying an alert (such as an angry face), playing a warning sound, and sending a wireless “alarm” message to another micro:bit.

For this activity students will use two micro:bits. One will act as the sensor device, placed in the area students would like to monitor. The other micro:bit acts as the receiver/alarm, altering the user when movement is detected.

Grade Levels: 3 - 12
Subject Matter: Algorithms, Physical Computing, Programming
Concepts: Programs and Algorithms, Computing Devices and Systems, Data and Information
Standards: 6-8.PA.1, 6-8.CD.2, 6-8.CD.3, K-2.PA.1, K-2.PA.2, K-2.PA.3, K-2.PA.4, 3-5.PA.2, 3-5.PA.3, 6-8.PA.2, 6-8.PA.3, 3-5.DI.1, 6-8.DI.1, 6-8.DI.2, 3-5.CD.1, K-2.CD.2, 3-5.CD.2
  • Average Rating: 0.0 (0 ratings)

Activity Instructions

  1. Introduce the Activity
    • Discuss:
    • How do security systems know when something has been moved?
    • What should happen if someone touches something valuable?
    • How could we be alerted from far away?
    • Today, we will be building your own motion-triggered alarm system using the BBC micro:bit.
  2. Introduce the System
    • This project uses TWO micro:bits working together.
    • Explain the roles of the two micro:bits:
      • One detects movement
      • One receives the alert
  3. Program the Alarm Function
    1. Walk students through creating the code or use the provided link to share the completed code with students.
    2. Model in MakeCode
      • Using the “on start” block add the following block inside:
        radio set group “1”
      • Using the “on shake” block add the following blocks inside:
        Radio send string “thief!”
        Call alarm
      • Within the “Advanced menu” Make a Function titled “alarm.” Using the Function “alarm” block add the following blocks inside:
        Show icon – angry face
        Play melody baddy in background
      • Using the “on radio received receivedString block” block add the following block inside:
        Call alarm
  4. Set Up Radio Communication – Now we connect both micro:bit devices
    • Download the code to BOTH micro:bit devices
    • Assign a micro:bit as the sender (the one hidden) and the receiver (the one that will alarm)
  5. Test the Detect Movement – Shake the micro:bit sender and wait for response on the micro:bit receiver
  6. Debug if necessary

Tips for Running Activity

  • Set Group & Channel: Always set a unique group number in on start to prevent interference, especially in classrooms. It might be best to assign and keep a list of assigned channels so groups know, and don’t accidentally select another channel. 
  • Power Levels: Adjust signal strength to increase range or lower it for debugging in confined spaces.
  • Handle Data Types: You can send strings (text) or numbers. For complex data, consider sending simple number codes and decoding them on the receiving end.
  • Receive and Display: The on radio received block allows the micro:bit to wait for messages, which can then be displayed using show string or show number.
  • Don’t forget to download code to BOTH micro:bits
  • Connection to Networks – A network is just a group of devices talking to each other. Your micro:bits formed a tiny wireless network—sending messages, receiving them, and reacting.

Assessment Opportunities

Reflection:

  • What was the input in your system?
  • How did the devices communicate?
  • Why are functions useful?
  • How could this system be improved?

Extension Opportunities

Students can:

  • Send different messages for different movements
  • Adjust sensitivity (use accelerometer values instead of shake)
  • Build a protective case or enclosure (maker connection)
  • Combine with other sensors (light, sound)
  • Create a multi-object alarm network

Elements of this resource were created by BBC micro:bit, then curated by the team at Nextech.

Learn More