13. Burglar alarms

Burglar alarms and security systems are well understood by the children who are aware that they serve a valuable function. This makes them a superb context for control projects.

Working on security systems is very engaging for children, particularly when they get to test them on their friends.

The selection of a sensor is often a starting point. The simplest sensor of all is some form of on/off switch. The switch provides a digital input. Usually on (1 or high) when triggered. A push to make switch works best.

Designing and making sensors for alarm systems is a great way to integrate electrical circuits into D&T.

Watch the video for some ideas.

Simple pressure pads can be made from aluminium foil. Reed switches when combine with magnets make a sensor to detect the opening or closing of a window.



For more sophisticated systems an analogue sensor can be used to detect the movement of a burglar by detecting changes in position, light, sound, pressure, or infrared.

The built in accelerometer can be used as a burglar sensor. It is very responsive to movement of the micro:bit in three different directions. For example, if the micro:bit is tilted to the left or to the right, the Python script below will display an L for left and an R for right and a buzzer connected to pin 1 will sound.

from microbit import *

while True:

reading = accelerometer.get_x()

if reading > 20:

display.show("R")

pin1.write_digital(1)

elif reading < -20:

display.show("L")

pin1.write_digital(1)

else:

display.show("-")

pin1.write_digital(0)

The LDR used in the bedside light project can be used in a light operated alarm. A buzzer can be used in place of the bedside light. One important difference is that the alarm must latch on. By that we mean that if the sensor is no longer, triggered, the alarm will continue to sound until it is reset (in this case by pressing button A).


Algorithm:

repeat forever

if sensor is triggered

alarm switched on

if reset button A is pressed

alarm switched off

PXT Editor script:

Micro Python script:


from microbit import *

while True:

if pin2.read_analogue() > 950:

pin1.write_digital(1)

if button_a.is_pressed():

pin1.write_digital(0)

PIR sensor

Many intruder alarm systems make use of a PIR or passive infra red sensor as a motion detector. In fact it is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. PIR sensors are increasingly used to control automated lighting systems to prevent lights being left on. This is another project you may wish to set for your children. To created an automated light system.

The PIR is a relatively cheap component that can be purchased for under £3.

The sensitivity of the PIR sensor can easily be adjusted using a small screwdriver.

The model:

The PIR component has three pins for connecting it to the circuit. Two are for power and should be connected negative to GND and positive to 3V. The third is for the signal wire and if using the script below should be connected to pin0.

BBC Block editor script:

The problem with this script is the alarm stops sounding if the burglar stands still. It needs a 'latch' to keep it on. Set this as extension challenge for more able pupils.