Reader small image

You're reading from  Building a Home Security System with Raspberry Pi

Product typeBook
Published inDec 2015
Publisher
ISBN-139781782175278
Edition1st Edition
Right arrow
Author (1)
Matthew Poole
Matthew Poole
author image
Matthew Poole

Matthew Poole is a systems engineer based near Southampton on the south coast of England, with over 20 years of industry experience. After graduating in electronics and communications engineering, he went on to train as and become an air traffic engineer for Civil Aviation Authority, UK, working on microprocessor-based control and communications systems. Later, he became a software architect and mobile technology specialist, working for several consultancies and global organizations in both hands-on architecture and product-management roles . He is now a partner at Connecting Objects, a boutique systems consultancy focusing on the design of Bluetooth and other wireless-based IoT systems, taking ideas from concept to prototype. He is also the Director of Technology for Mobile Onboard, a leading UK-based transport technology company specializing in bus connectivity and mobile ticketing systems. He is also the author of Building a Home Security System with Raspberry Pi, Packt Publishing. You can find his blog at http://cubiksoundz.com and LinkedIn profile at https://www.linkedin.com/in/cubik, or you can reach him on Twitter at @cubiksoundz.
Read more about Matthew Poole

Right arrow

Chapter 5. Adding a Passive Infrared Motion Sensor

In the previous chapter, we started adding basic but commonly used magnetic switch sensors to our home security system and reading their status to protect doors and windows from intrusion. We also looked at how we can divide our home into zones, such as by individual rooms, so that we can group our sensors into logical circuits, which can then be identified as part of these zones rather than as individual sensor inputs.

We will now add motion sensors to our system in the form of Passive Infra-Red (PIR) detectors. These detectors come in a variety of types, and you may have seen them lurking in the corners of rooms. Fundamentally, they all work in the same way, which is detecting the presence of body heat within a certain range; so, they are commonly used to trigger alarm systems when somebody (or something, such as a pet cat) enters a room.

A typical PIR motion sensor (type GardScan QX-PIR)

In this chapter, we will:

  • Learn how PIR detectors...

Prerequisites


You'll need the following parts for this chapter (apart from the components used in the previous chapter):

  • A passive infrared detector, the wired type (this is available from any DIY store)

  • A 4N25/4N35 opto-isolator

  • A 1N4148 diode

  • A 1-Kohm resistor

  • A 10-Kohm resistor

  • A 433 MHz receiver module and remote transmitter (this is optional)

  • A 12V power supply

  • A hook-up wire

  • A 6 core alarm wire

Passive infrared sensors explained


You might not realize it, but all objects radiate heat energy (including your coffee table); it's just that you can't see it because heat consists essentially of infrared waves, which are invisible to the human eye (exactly the same as your TV remote control). These waves can, however, be detected by electronic devices designed for such a purpose, such as the infrared receiver in your TV that detects the energy emitted by your remote control when the buttons are pressed.

You probably do realize, however, that living things such as us, our cat, and the mouse under the floorboards generate quite a bit of heat. Passive infrared motion sensors used in security systems and automatic lights are designed to detect this level of heat. The term passive is used because the sensors themselves do not radiate any energy for detection purposes—instead, they just detect the infrared radiation emitted by objects. This is notably different from devices such as ultrasonic...

Give me power (again)


Before we can go on to connect off-the-shelf security devices to our alarm system, we need to have a power supply that's compatible with such devices. Typically, alarm circuits and their devices use a 12V supply with enough current to drive all the devices and the alarm control system itself.

Fortunately, this is not too difficult to sort out, but it is something we need to do now; otherwise, we won't be able to connect and power our PIR sensors. The easiest way to do this is to buy a high-quality 12V mains adapter that provides a nice regulated supply. These are readily available from online stores or electronics suppliers. Alternatively, you can build your own 12V regulated supply and add it to the power supply strip board that we built in Chapter 3, Extending Your Pi to Connect More Things.

Note

Another option is to use battery-powered PIR sensors, which means that you wouldn't have to power the unit from the security system's panel itself; however, it obviously also...

Connecting our PIR motion sensor


Commercially available alarm systems connect to their devices using a 4 core or 6 core alarm cable. In the previous chapter, we used a 4 core cable because we were connecting a switch that needed two wires plus an antitamper loop, which needed another two wires.

For our PIR sensor circuit, we need the same four wires; however, we also need to send power to the device from the control panel, so an additional two wires are needed for this—hence the requirement for a 6 core cable.

The following diagram shows the wiring connections for my GardScan PIR sensor, but this is in fact typical for most off-the-shelf security system devices:

Typical connections for security system sensor devices

Similar to the magnetic contact sensors that we looked at in the previous chapter, devices can come with either a normally closed (NC) or a normally open (NO) alarm. This particular device has a normally closed output, which means that the alarm circuit will be broken when the detector...

12V alarm zone circuits


Making our zone circuits use 12V instead of 3.3V is as simple as changing the power supply, and in fact all of sensors we used so far can handle 12V power passed through their switches.

However, if we were to present the 12V circuit to the inputs on our GPIO port on the Raspberry Pi or our port expander, we would expect to see some magic smoke and smell something burning. So, we need to add some circuitry that allows us to use 12V alarm circuits as well as protect our control board inputs.

Alarm circuit protection

An effective way to protect our zone inputs from 12V alarm inputs is to use a little low-cost device called an opto-isolator. As the name suggests, this isolates the alarm circuit from the digital inputs of the control board using light.

Inside an opto-isolator (also called an opto-coupler) is an infrared LED, which transmits light to a photo-transistor when a current is passed through it, thus switching it on. The circuits are electrically isolated as they...

Wireless PIR motion sensors


Wireless motion sensors are now commonly available at a low cost, allowing them to be installed practically anywhere without any wiring from the alarm control panel. Some of them still require an external power supply, but many operate on batteries. The alarm system must contain a wireless receiver compatible with the wireless sensor.

In this section, we'll take a look at how we can use our Raspberry Pi-based security system with wireless receiver devices.

433-MHz wireless alarm systems

Wireless systems use an unlicensed radio frequency to communicate between the various components of an alarm system. In the UK, the two most popular frequencies used are 433 MHz and 868 MHz. While the more recent systems now use the 868-MHz frequency, 433 MHz is still in widespread use as it has a slightly longer range than an 868-MHz system. However, the 433-MHz band is also used by many other devices, which makes it congested, whereas 868 MHz is generally used only for alarm systems...

Logging detection data


With any system, it's useful to be able to log data when something happens. We can do this with our detectors too by writing to a log file every time a detector in a zone is triggered. This way, you can keep a log of every time someone enters a room, which you can review at a later date even if the system isn't armed. You can also keep a log of when the system is armed and disarmed.

Here's a simple script that shows you how to do this whenever an event happens on our zones connected to the GPIO inputs:

#!/bin/bash

#set up the I2C expansion port
sudo i2cset –y 1 0x20 0x00 0xFF

#reset status
CURR_STATE="0x00"
LAST_STATE="0x00"

#path to the log file
LOG_FILE="/etc/pi-alarm/zones.log"

# loop forever
while true
do
  # read the gpio inputs
  CURR_STATE=$(sudo i2cget –y 1 0x20 0x12)
   
   #check if state has changed
   if [ "$CURR_STATE" != "$LAST_STATE" ]
  then
    #write change to log file
      TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
     echo "$TIMESTAMP Zone Status...

Summary


In this chapter, we started off by learning how passive infrared sensors are used to detect motion to protect a predefined coverage area from intrusion. We then looked at connecting these to the inputs on our port expander via opto-couplers as we will now use 12V to power the alarm zone circuits.

We then looked at wireless alarm systems that operate on the open 433-MHz band, which is commonly used for security devices. After exploring the possibility of using the legacy 433-Util bit-banging software on our Raspberry Pi to decode the signals transmitted by devices using a simple receiver, we opted to use a paired receiver device that will interface easily with our alarm circuit inputs.

Finally, we created a simple script that will log the changes in our alarm inputs to a text file, which can later be expanded to log exactly what's going on with the system in detail.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Building a Home Security System with Raspberry Pi
Published in: Dec 2015Publisher: ISBN-13: 9781782175278
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Matthew Poole

Matthew Poole is a systems engineer based near Southampton on the south coast of England, with over 20 years of industry experience. After graduating in electronics and communications engineering, he went on to train as and become an air traffic engineer for Civil Aviation Authority, UK, working on microprocessor-based control and communications systems. Later, he became a software architect and mobile technology specialist, working for several consultancies and global organizations in both hands-on architecture and product-management roles . He is now a partner at Connecting Objects, a boutique systems consultancy focusing on the design of Bluetooth and other wireless-based IoT systems, taking ideas from concept to prototype. He is also the Director of Technology for Mobile Onboard, a leading UK-based transport technology company specializing in bus connectivity and mobile ticketing systems. He is also the author of Building a Home Security System with Raspberry Pi, Packt Publishing. You can find his blog at http://cubiksoundz.com and LinkedIn profile at https://www.linkedin.com/in/cubik, or you can reach him on Twitter at @cubiksoundz.
Read more about Matthew Poole