Step 1: Make it
What is it?
Keep your precious things safe with this radio-controlled burglar alarm.
These two videos show you what you'll make and how to code it:
Introduction
Coding guide
How it works
- When the micro:bit is shaken, the accelerometer detects movement and it shows an angry face on the LED display and plays an alarm sound.
- It also sends a ‘thief!’ radio message, so that another micro:bit can warn you if someone is moving your valuable object.
- If you have two micro:bits, flash this program onto both. Put one in, or on, a valuable thing you want to protect and keep the other near you. Connect a buzzer or speaker to the one you keep near you.
- As we want to show the angry face and play the ‘BADDY’ tune on both the movement sensor micro:bit and the alarm, this program uses a function (or procedure) called alarm.
- Procedures and functions are really useful for sections of code we want to use at different points in a program. It saves duplicating code and makes the program more compact and efficient.
What you need
- 1 or 2 micro:bits
- a battery pack if using 2 micro:bits
- something precious to keep safe
- optional headphones, buzzers or powered speakers and 2 crocodile clip leads to attach them
Step 2: Code it
Step 3: Improve it
- What else could you protect with an alarm like this? How could it help protect trees?
- Make it more sensitive using accelerometer readings or other gestures.
- Split the program in two, so you have different programs on the sensor on your valuable thing and on the alarm you keep with you.
- Send different messages and show different pictures for different alarm sensors on different valuable objects.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.