Feed on
Posts
Comments

I’ve previously bought an alarm system from Ebay and have been making modifications to it such as making the PIRs wireless and added wireless sirens. On our last part, we added a way to check which sensors have checked in.

By using everything that we’ve built and modified, it’s now time to make our own alarm system. We’ll be adding in our own PIR, Door sensor, making a slight change to the Siren and modifying the Server.

PIR Sensor

IMG_3267

I was thinking about how I could potentially box up the PIR with the PCB but I found that the PIR module you buy from Ebay fits in nicely to the existing casing, I removed the PIR cover and it works well. I’ll be switching from the 3V coin cell to a 3.7 Li-poly so that the PIR and the PCB will run off this which should last at least a few years.

IMG_3308 IMG_3309

One down side of running from the Li-poly battery is that after testing I found that the PIR is unstable when the voltage drops to 3.3V the PIR automatically turns on. One thing I should have added a while ago was a way to monitor the battery voltage, so we’ll add that this time and the cut off will be 3.5V. A few cuts on the PCB, adding some resistors, re-wiring and it’s ready to go.

If the PIR detects movement, we could modify the existing way to communicate to the server to have the PIR ask the server for a random number, the PIR does a SHA1 with HMAC on it and send that it’s detected movement but this has timing issues. We need a way to send a single command to the server which is where a rolling code comes in, similar to the ones that car remotes use.

Both the server and PIR start off with a 128bit random number, when the PIR checks in, the server provides how many increments to add to the random number. If movement is detected, the PIR can now increment the random number however times the server has previously sent, SHA1 the random number and send that to the server who can verify it the same way.

Here we’ve got the rolling code base number and the rolling code that gets copied over and the rolling code addition. This transaction will only happen if the alarm goes off, so very rarely (or never I hope!), so I’ve just gone with a 16bit increment.

If movement is detected, we skip the 8 second sleep. We firstly remove the PIR interrupt so it won’t interrupt us, check the battery voltage and if it’s below 3.5V then we remove the interrupt and turn everything off, otherwise we turn the interrupt back on. In the chance that the PIR went high in-between the ADC reading, we’ll check it manually.

If movement is detected, we set all our data out to the alarm triggered type, set up the rolling code, SHA1 it and then transmit it a few times to the server so we know it will definitely receive it.

We now do what we normally do when checking in, SHA1 the 256bit random number, add in the sensor type, sensor number and now add in the battery voltage. Later on in this project, we could have the server light up some LEDs to show which sensors have checked in and which ones have the batteries are low.

When the pin interrupt is triggered, we check what it’s for, the battery low or PIR high or low.

Door Sensor and Siren

IMG_3273

The door sensor uses the same code as the PIR except that we’re using a reed switch with a pull down of 1M, so when the magnet is close to the reed switch, the pin reads high, otherwise it’s low. I can grab the reed switch from the existing door sensor and should be able to re-use the casing too. I’m thinking of running the door sensor off a 3V coin cell because a Li-poly won’t fit well so I may increase the check in time to once every 30 – 60 seconds to increase the battery a bit.

The siren remains mostly unchanged except for changing how we send our sensor type and number.

Server

For the server, the main part is just listening for incoming requests which remains unchanged.

When a sensor checks in, we check if it’s a PIR or Door sensor and if the alarm isn’t on. We add in the system state, rolling code and the SHA. For the siren request, it’s mostly the same as you can see.

We’ll need a remote control to turn the system on and off but but I haven’t built it up just yet, though it’s going to have a similar type of rolling code to the PIR does except that it’ll be 32bit as the remote everyday. When you push the button it will ask the server for the latest rolling code and afterwards it can send the rolling code to the server, this way we don’t need a large capacitor

If the remote control is now sending the rolling code, we verify it, increment the rolling code and then turn the system on or off. Similar code would apply to the PIR’s rolling code.

Download AlarmSM_v2.0

For the next part we’ll look at adding the remote, adding the LEDs to the server, adding battery backup to the server and testing it all out. I’ve also been thinking I could use RFID cards instead of the remotes or perhaps have that as another option of entry as well.

Part 1
Part 2: Two way communication for PIR sensors
Part 3: Secure communication
Part 4: Adding on sirens and SMS sending
Part 5: Modifying the PIR sensor
Part 6: PIR PCB
Part 6.5: PCBs arrived
Part 7: See which sensors check-in
Part 8: Building our own alarm system
Part 9: Remote control and attempted improvements
Part 10: Prototype PCBs

Leave a Reply