In this post we are going to have a look at how we might go about making an intruder alarm using a Raspberry Pi and the Pibrella add-on board.
You will need a Raspberry Pi and a Pibrella board connected directly or via a ribbon cable, IMPORTANT: don’t push too hard, get the pins lined up and push steadily and firmly.
Firstly, you need to open Python (IDLE) on the Raspberry Pi.
Then click File > Open > alarm.py
In this Python window, we are going to program a working intruder alarm using the code from the master file below.
Make sure the code looks exactly as shown, the smallest of mistakes will cause your code not to run or give unexpected results.
SAVE your file as alarm
Now you need to wire up the alarm so that we have a working ‘live’ circuit.
Using the jumper wire provided, connect both the ‘A’ terminals together. This will act as our door or window contact.
When you have saved the file and wired the contacts, open LX Terminal from the desktop, when the terminal opens type:
sudo python alarm.py then press ENTER
sudo allows us to run commands as a super user so we can have access to the GPIO pins, python tells the system to run the next file in the python environment and alarm.py is the file that should be opened.
Your intruder alarm is now active, to test it works, remove one end of the wires from the contact, your lights should flash and the alarm should go off, like in the video below. If it doesn’t work, your code may have an error which will need to be found and fixed, more debugging!
To reset the alarm, simply press the button.
– You could try and modify the code so that the alarm is intermittent
– Then you could try to change thecode further by altering the frequency of the buzzer to make it a two tone alarm (tip: use different values in the brackets of the buzz command)
Using the Pibrella board with a Raspberry Pi you can control lots of other devices like PIR sensors, control motors, and lots more.
Intruder alarm code taken from http://www.pibrella.com.