Step 1: Make it
What is it?
Keep your precious things safe with this radio-controlled burglar alarm.
How it works
- Flash this program onto two micro:bits. Put one in, or on, a valuable thing you want to protect and keep the other near you. Connect a buzzer or speaker if you have one.
- When the micro:bit is shaken, the accelerometer detetcs the movement and it shows and angry face on the LED display and plays an alarm sound. It also sends a ‘thief!’ radio message, so that the other micro:bit will warn you if someone is moving your valuable object.
- 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
- 2 micro:bits, at least one with a battery pack
- something precious to keep safe
- optional headphones, buzzers or powered speakers
Step 2: Code it
Step 3: Improve it
- 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.