Skip to content

Activity

Pressure switch alarm

Advanced | MakeCode, Python | LED display, Pins, Radio, Sound | Electricity, Electronics, Input/output, Radio waves, Selection, Sensors

Step 1: Make it

What is it?

Create a wireless intruder alarm that will warn you when someone steps on a home-made pressure sensor.

Sensor micro:bit with pin 0 connected to one foil pad, GND pin connected to another. A flap of cardboard with foil folds over and connects the two other foil pads when someone treads on it.

How it works

  • Flash the sensor program onto a micro:bit.
  • Make a pressure input switch out of cardboard and tin foil like in the picture. Fold it over and place it under a rug or carpet. You may need to add some foam to keep each side apart. Connect the two foil pads on one side to pins 0 and GND on the sensor micro:bit. When you step on it, the foil on the top completes an electrical circuit, and it sends an ‘intruder’ radio message.
  • Flash the alarm program on to the other micro:bit (the alarm) and attach a buzzer or speaker to pin 0 and GND if you have one. When it receives the ‘intruder’ message it shows an angry face on the LED display and plays an audible alarm sound. Press button A to clear the display.

What you need

  • 2 micro:bits and at least 1 battery pack
  • 2 crocodile clip leads
  • tin foil, scrap cardboard, glue, scissors, foam
  • optional buzzer, amplified speaker or headphones and 2 crocodile clip leads

Step 2: Code it

Sensor / transmitter:

1from microbit import *
2import radio
3radio.config(group=34)
4radio.on()
5
6while True:
7    if pin0.is_touched():
8        radio.send('intruder')
9

Alarm / receiver:

1from microbit import *
2import music
3import radio
4radio.config(group=34)
5radio.on()
6
7while True:
8    message = radio.receive()
9    if message:
10        if message == 'intruder':
11            display.show(Image.ANGRY)
12            music.play(music.BADDY)
13    if button_a.was_pressed():
14        display.clear()
15

Step 3: Improve it

  • Add multiple sensors each sending its own message, e.g. ‘room1’, ‘room2’ and have the alarm show where the intruder is.
  • Try different designs for the pressure switch. For example, place a foam pad inside it if is being triggered too easily.
  • You could make a rain alarm using two tin foil pads very close together – if they get wet, they will trigger the alarm. Be sure not to get your micro:bit wet though!