Introduction: Home Guarduino - IoT Connected Security System
PROBLEM: We moved into a new house a couple of years ago, and it already had a security system installed. Problem was that nobody knew the password! The previous owners never used it, and the manufacturer had gone out of business. Despite extensive internet searches, and even consulting a security expert, the system remained a 'brick on the wall'.
SOLUTION: A perfect opportunity for DIY.
I wanted to use the use the already installed wired PIR motion sensors and smoke detectors, I wanted the Main Panel and Keypad to be 'drop in replacements' for the existing units, and I also wanted to add some extra features like card access and internet connectivity.
- 8 programmable tamper-proof zones (fire or burglar)
- RFID card or tag arming/disarming
- Internet connection via home wifi which logs all activity to the web
- Secondary wifi connection to a permanent cellphone hotspot
- Sends notifications (eg phone call and email) when alarm is tripped or fire detected
- Battery backup if AC power cut
- 5 programmable digital zones (for addition of wireless sensors at a later stage)
Step 1: Overview
My aim was to produce a security system as near to professional quality as possible - so I had to research best practices for home security systems. This involved understanding of tamper-proof zones, debouncing to reduce false alarms, and backup battery charge circuits, among other things. I am not a security expert, so please let me know if I got any of this stuff wrong.
The Keypad Unit is based around a Arduino Nano, interfaced to a 16x2 LCD display (via a shift register to minimize the number of digital pins used), an RFID module and a 4x4 keypad, with a bi-colour LED and piezo buzzer for feedback. The Keypad communicates via serial link to the Main Panel.
The Main Panel is also based around an Arduino Nano. Linked via serial comunicatiion with the Keypad Unit and also (via soft serial) to a EPS8266 wifi connection. Analogue inputs are used for the tamper proof zones. Two relays are employed - one for the siren and one to cut the power to wired sensors on reset (some sensor types require this).
A bridge rectifier and series of regulators provide 12v, 5v and 3.3v power and a trickle charge to the backup battery.
Events are logged via wifi (ESP8266) to a ThingSpeak IoT channel (thinkspeak.com). This channel records changes in status (eg alarm armed, alarm triggered etc), changes in wifi and ac power availability, and also which zones have triggered an alarm.
ThinkSpeak can be configured so that various tasks occur for specific events. My system will email me (via PushingBox) and call me on my cell phone with a predefined message (via Twilio) if the burglar or fire alarms are activated. But you could do many other things - like send a txt or a tweet.
Step 2: Keypad Unit
The PCB for the Keypad is single sided 72mmx70mm and was made using the 'iron on' laser printed technique, (details of which can easily be found elsewhere) and drilled with a highly sophisticated drilling apparatus (www.instructables.com/id/Cheap-PCB-Drillpress-for-Dremel) of my own design.
The fit into the case is a tight one, and I moved the LED and buzzer off-board. Note that I left the protective plastic on the buzzer because it was too loud if I removed it! The case was also modified so that it could be opened and closed using two screws placed at the bottom. The screws screw into nuts that are mounted on the outside cover with two pieces of plastic and glue. They screw up into two aluminium brackets to hold the case closed.
The RFID module fits nicely into the smaller case and is stuck to the wall with padded two sided tape.
The artwork was colour laser printed onto clear labels and attached to the cases.
1 x 5mm bi-colour LED
1x 4x4 16 button keypad http://www.ebay.com/itm/Data-Keypad-Switch-4-x-4-White-Key-Security-Pad-16-Momentary-Door-Entry-Button
1x 16x2 LCD Display http://www.ebay.com/itm/1602-16x2-Character-LCD-Display-Module-HD44780-Controller-Blue-Blacklight
1x MRFC522 RFID board http://www.ebay.com/itm/MF522-AN-module-RC522-RFID-Radiofrequency-IC-Card-with-Sensor-Reader-Arduino
1x Active Buzzer Alarm Module (not passive as per schematic) http://www.ebay.com/itm/Active-Buzzer-Alarm-Module-Sensor-Beep-for-arduino-smart-car-new
1x PN100 or equivalent transistor
1x 10K trimpot
1x 1K resistor
2x 220R resistors
1x Arduino Nano V3.0 ATmega328 5V
2x each 3pin, 6pin & 8pin headers
2x 2-way screw terminals
1x small case (18x45x70mm) http://www.ebay.com/itm/2pcs-NEW-White-Plastic-Electronic-Project-Box-Enclosure-case-DIY-18x45x70mm
1x large case (25x90x135mm) http://www.ebay.com/itm/RF20070-ABS-Plastic-Enclosure-for-Electronics-Connection-Box-Project-Case-Shell
Step 3: Main Panel
The Main panel PCB is single sided 180mmx120mm and was made the same was as the Keypad PCB.
Note the two 3-pin headers with 2-pin movable jumpers, one is for master reset, and the other is to allow updating of the firmware on the ESP8266 (but this function not implemented in the Main Panel firmware yet).
The ATTINY85 and RF Reciever can be left off, as these are for yet-to-be-implemented wireless sensors.
Five digital inputs (zones 8 to 12) are also available on the expansion header - if you have a use for these. When programming the panel, NO means normally logic 0, and NC means normally logic 1 for the digital zones. Note that these are not tamper-proof, and so should only be attached to modules (a wireless-sensor receiver, for example) contained within the Main Panel housing.
1x 7805 regulator
1x LM3940IT3.3 regulator
1x LM317 regulator
4x 0.1uf capacitors
1x Green LED
1x Red LED
4x 100R resistors
8x 10K resistors
1x 500R trimpot
1x 220R 5W wirewound
2x 2N7000 mosfet
1x PN100 or equiv transistor
1x 500mA PTC fuse
8x 1N4733 5.1v zener
14x 2-way screw terminals
1x Arduino Nano V3.0 ATmega328 5V
1x ESP8266 Serial Esp-01 WIFI Module http://www.ebay.com/itm/ESP8266-Serial-Esp-01-WIFI-Wireless-Transceiver-Module-Send-Receive-LWIP-AP-STA
2x 5V One 1 Channel Relay Module Board Shield http://www.ebay.com/itm/310566336050
ADDITONAL PARTS (for wireless sensor connection - not required as not yet implemented)
1x 433Mhz RF Reciever Module http://www.ebay.com/itm/433Mhz-RF-Transmitter-Module-and-Receiver-Link-Kit-for-Arduino-ARM-MCU-WL
1x 2 DIP switch
ADDITIONAL PARTS (not required if replacing an existing unit as I did)
1x SA12-7 Sealed Lead Acid Battery 12V7.0AH/20HR
2x In-line fuse holders with 1A quick blow fuses
15VAC Power supply or transformer
1x Lockable Metal Wall-Mounted Case 230x260x80mm
1x 12V Exterior Siren & Strobe Light
1x Interior Siren
2x Insulated heatsink mountings for regulators
PIR sensors (12 volt) and Smoke detectors(12 volt) as required
Step 4: IoT Connectivity (ThingSpeak, PushingBox, Twilio)
STATUS LOGGING - THINGSPEAK CHANNEL
You need to create a ThingSpeak channel before you upload the firmware to the Main Panel. This is because your ThingSpeak key will be hard-coded into the firmware.
Go to thingspeak.com and create an account (it is free). Then click on the channels tab and then the new channel button. Set up the channel (ALARM_MONITOR) with four fields in the same order as shown:
Field 1 - Status
Field 2 - AC
Field 3 - Wifi
Field 4 - Zone
One you have created the channel, select the API Keys tab and take a copy of your 16 character API Key - this will be entered into the firmware later.
Alarm status will be logged to the ThingSpeak channel every hour, and any time that there is a change in status. The values logged into Field 1 are:
STATUS_READY 0 (ready / not ready)
STATUS_ALARM 9 (burglar alarm)
STATUS_FIRE 10 (fire alarm)
This is all you need to do to simply have a log of events, but typically you will want to be contacted if an alarm trips. I will show you how to set up ThingSpeak reacts that will send an email (via pushing box) and a phone call (via Twilio). I will show you two examples: email when burglar alarm activated and phone call when fire alarm activated.
EMAIL NOTIFICATION - PUSHINGBOX
You will need a google account. Go to pushingbox.com and login with your google account.
Select My Services and press the Add a Service button. Select Email and enter your email address and give your service a name.
Select My Scenerios and add a new scenerio. Press Add an Action, and then select your email service. Type the contents of the email notification that you want sent. Note the DeviceID for your scenerio - you will use this in ThingSpeak. (I have two scenerios - one that sends a burglar alarm notification and one for the fire alarm).
Back in ThingSpeak, select Apps, then ThingHTTP, then New ThingHTTP.
Setup your ThingHTTP like this (some entries are blank):
Name:Send email ALARM
HTTP Auth Username:
HTTP Auth Password:
Body:devid=XXXXXXXXXXX [XXXXXXXXX= PushingBox Scenerio DeviceID]
You can test this by pasting the url generated on the right hand side of the page into a browser (leave off the 'GET' at the beginning). You should receive your email notification.
In ThingSpeak select Apps, then React, then New React.
Now you set up a React so that your Send email ALARM ThingHTTP is activated when the Status field becomes equal to 9, which is STATUS_ALARM (ie burglar alarm). See the picture for exact details.
PHONE CALL NOTIFICATION - TWILIO
You will need to sign up for a Twilio account at www.twilio.com. It is free to signup, but costs to purchase phone numbers and to make calls. On your account dashboard there will be anAccount SID and an Auth Token that you will need later.
Click on the # (phone numbers) icon on the left. Here you will need to purchase a phone number using the Buy a Number option, and you will also have to verify your cellphone number using the Verified Caller ID's option.
Back in ThingSpeak, select Apps, then ThingHTTP, then New ThingHTTP.
Setup your ThingHTTP like this (some entries are blank):
Name:Phone call FIRE
HTTP Auth Username: XXXXXXXXXX
HTTP Auth Password: YYYYYYYYYY
Replace XXXXXXXXXX with your Twilio Account SID
and YYYYYYYYYY with your Twilio Auth Token
and +ZZZZZZZZZZ with your verified cellphone number
You also need to provide a url to a text file that contains the content of your phone call (via text to speach).
Mine are http://cr8software.net/fire.txt and http://cr8software.net/alarm.txt. You can use these links, but I cannot guarantee that they will always be available. Best to upload your own text files somewhere.
You can test that the call works by pasting the url generated on the right hand side of the page into a browser (leave off the 'GET' at the beginning). You should receive a phone call notification.
Now in ThingSpeak select Apps, then React, then New React.
Now you set up a React so that your Send phone FIRE ThingHTTP is activated when the Status field becomes equal to 10, which is STATUS_FIRE. See the picture for exact details.
NOTFICATIONS - PHONE APP
An alternative to setting up ThingSpeak Reacts (with email and phone notifications), is to use a phone app which monitors your ThingSpeak Channel. There are several available. eg ThingView Free or IoT ThingSpeak Monitor Widget, which are available from the Play Store.
Step 5: Firmware
Before attaching the Keypad to the Main Panel, upload the firmware.
The Keypad firmware requires the following libraries:
Once you have uploaded, you can connect to it with the serial monitor to check that it is working properly.
Type some characters on the Keypad, when you press one of the alpha keys (A, B, C or D), a string of characters should be sent to the serial monitor.
Try typing some commands in the serial monitor to check that the Keypad responds:
>READY (will show "ready" on the display)
!BEEP1 (will make a sound)
If all is working, then move on to the Main Panel.
MAIN PANEL FIRMWARE
The Main Panel firmware requires these libraries:
Before uploading you will also have to enter some information into the sketch (around line 121):
#define SSID1 "XXXXXXXXXX" //Primary WIFI network name
#define PASS1 "XXXXXXXXXX" //Primary WIFI network password
#define SSID2 "XXXXXXXXXX" //Secondary WIFI network name
#define PASS2 "XXXXXXXXXX" //Secondary WIFI network password
String GET = "GET /update?key=XXXXXXXXXXXXXXXX";
//Replace XXXXXXXXXXXXXXXX with your ThingSpeak "Write API Key" for your Alarm Channel
Once you have uploaded again you can test with serial monitor. Enter ? into the serial monitor, and the Main Panel should respond with >READY.
Step 6: Installation
Hopefully the diagrams are self-explanatory for connecting things up.
The Keypad and sensors are connected to the Main Panel with 4 core alarm cable (black, red, white, blue).
I am not sure of the maximum advisable distance for the connection between the panel and keypad (mine is just through the wall), but the sensor cables should be able to handle wiring all around the house. Powered sensors (like PIR sensors and smoke detectors) should take their power via the Aux Reset relay, as some sensors need to be powered down to reset (the Aux Reset relay will open for 5 seconds when the panel resets).
Before connecting the battery adjust the trimpot to get a suitable charge voltage at the battery terminals. My battery states 13.6 - 13.8 volts as an acceptable range, and I have set my trickle charge voltage at 13.65 volts. Make sure you set the voltage to match your battery and seal the trimpot with a glue gun.
The 12v and 5v regulators need to a heatsink as they will get warm even with the heatsink attached to the metal cabinet. Make sure the heatsink is insulated from the regulators with bushes.
The zones are 'supervised' (ie tamper proof), and require single End Of Line Resistors of value 1K2 as shown in the diagram. This is a standard type alarm configuration with three states (open, closed, and 1k2 resistance). 1K2 resistance across the zone terminal is the untriggered state. Open and closed circuits will either mean the alarm has been triggered, or the cable has been shorted or cut. You can have one or more sensors per zone.
I recommend having a button that will trip when the Main Panel cabinet is opened. You can see this in the upper right of the picture. This is connected to a zone that has a 0 second trigger delay, and set to cause a 'not-ready' status if open. The cabinet should also be lockable. This is so the alarm will trigger and send a notification before anyone has time to disable it.
INITIAL POWER UP
When powering up for the first time, put the reset jumper (middle top of panel) in the upper position. The display should read MASTER RESET. Enter #0200D into the Keypad, this will save all the defaults to the EPROM. Put the jumper back in the lower position and do a manual reset using the button on the Main Panel Arduino.
The alarm is now ready to program.
Step 7: Operating Instructions
There are two four digit passwords:
USER password (default 0123, denoted UUUU below) - everyone who needs to arm and disarm the alarm will have this
MASTER password (default 9999 - denoted MMMM below) - used to program the system, generally only one person will know this
Enter MMMMB (will be 9999B initially, after reseting to defaults) into the keypad to enter programming mode. The display will say PROGRAM.
PROGRAM GLOBAL ATTRIBUTES
To program global attributes enter #99B (ie zone 99). Then to list the current values enter *B
To change an attribute enter n*mmB , where n=attribute and mm=value. eg to change the master password to 7890, enter 0*7890B
0 - Master passcode (4 digits) 
1 - User passcode (4 digits) 
2 - Exit time (seconds, 0-255) 
3 - Log Wifi 0=no 1=yes 
4 - Action when fault/tamper occurs on a zone 0= no action 1=error 2=alarm 
5 - Debug level 
6 - Siren duration (minutes, 1-255) 
Notes: Values in [ ] are defaults. Exit time is the number of seconds you have to leave the house once the alarm is armed.
PROGRAM RFID CARDS
Enter#90B (zone 90) to program cards. Swipe a card to add it to the list of accepted cards (maximum of 5). Swipe a card, then press D to delete a card
Enter #xB to program Zone x attributes (0-12 allowed, zones 8-12 are digital zones on the expansion header). Enter *B to list the current atttributes for that zone.
0 - NO/NC 0=NO 1=NC 
1 - Mode 0=Not Used 1=Alarm 2=Fire(24hrs) 3=Silent 99=disabled 
2 - Debounce count (cycles 250ms) 
3 - Trigger Delay (seconds) 
4 - Cause NOT READY mode if triggered? 0=no 1=yes 
Notes: Mode 1 (Alarm) can trigger only when alarm is armed. Mode 2 (Fire) can trigger at any time.
Debounce count is the number of 250ms cycles that the sensor has to be activated for before alarm will trigger.
Trigger delay is the countdown to siren after sensor is triggered.
If attribute 4 is set to 1, then the alarm cannot be armed if the sensor is currently triggered.
After a master reset, Zone 0 will be configured for NC, other Zones will be configured 'Not Used'.
Zone 'Disabled' means that the zone is disabled only until the next reset. Use 'Not Used' for any unused zones.
OTHER PROGRAM COMMANDS
101*B - display the real-time status of all zones. Press C to exit this mode. 0=normal, 1=triggered, 2=fault
102*B - display the wifi and ac status (after a short delay)
199*B - reset (same as ####D)
200*B - test siren for 1 second
*#*#D - Main Panel offline (turns off the Main Panels serial port). Do this when updating Keypad firmware. You will need to do a manual reset (press button on main panel Arduino) afterwards.
*#*#B - Keypad offline (turns off the Keypad serial port). Do this when updating Main Panel firmware. Enter ####D to reset afterwards
EXIT PROGRAM MODE
*D - Save any changes to EPROM and exit programming mode
#D - Cancel any changes and exit programming mode
TO ARM: enter user password and press 'A' eg UUUUA
OR swipe a programmed RFID card then press 'A'
Note that the Keypad must display READY before you can arm.
TO DISARM: enter user password and press 'D' eg UUUUD
OR just swipe a programmed RFID card
If the alarm siren has been activated then entering UUUUD will disarm the alarm and deactivate the siren. NOTE: If the siren was triggered by a Fire(24hrs) zone, then that zone will now be disabled to prevent re-triggering. Do a system reset to re-enable all zones (# # # # D see below).
* * * A - will manually activate the fire alarm (can enter at any time)
# # # # D - will do a system reset (ready/not ready or programming mode only)
Step 8: Maintenance
Check that your alarm is functioning properly maybe once a month or so.
Use a smoke detector test spray (eg CRC Smoke Test) to test that the smoke detectors are functioning (don't use an open-flame to test!) , and that the siren activates.
Check that the PIR sensors trip the alarm and that you receive the correct notifications.
Make sure you have credit in your Twilio account.
Most importantly, make sure you warn other family members (especially wife) before you test the siren!