You are previewing Building a Home Security System with Raspberry Pi.
O'Reilly logo
Building a Home Security System with Raspberry Pi

Book Description

Build your own sophisticated modular home security system using the popular Raspberry Pi board

About This Book

  • This book guides you through building a complete home security system with Raspberry Pi and helps you remotely access it from a mobile device over the Internet

  • It covers the fundamentals of interfacing sensors and cameras with the Raspberry Pi so that you can connect it to the outside world

  • It follows a modular approach so that you can choose the modules and features you want for your customized home security system

  • Who This Book Is For

    This book is for anyone who is interested in building a modular home security system from scratch using a Raspberry Pi board, basic electronics, sensors, and simple scripts. This book is ideal for enthusiastic novice programmers, electronics hobbyists, and engineering professionals. It would be great if you have some basic soldering skills in order to build some of the interface modules.

    What You Will Learn

  • Understand the concepts behind alarm systems and intrusion detection devices

  • Connect sensors and devices to the on-board digital GPIO ports safely

  • Monitor and control connected devices easily using Bash shell scripting

  • Build an I/O port expander using the I2C bus and connect sensors and anti-tamper circuits

  • Capture and store images using motion detectors and cameras

  • Access and manage your system remotely from your mobile phone

  • Receive intrusion alerts and images through your e-mail

  • Build a sophisticated multi-zone alarm system

  • In Detail

    The Raspberry Pi is a powerful low-cost credit-card-sized computer, which lends itself perfectly as the controller for a sophisticated home security system. Using the on-board interfaces available, the Raspberry Pi can be expanded to allow the connection of a virtually infinite number of security sensors and devices. The Raspberry Pi has the processing power and interfaces available to build a sophisticated home security system but at a fraction of the cost of commercially available systems.

    Building a Home Security System with Raspberry Pi starts off by showing you the Raspberry Pi and how to set up the Linux-based operating system. It then guides you through connecting switch sensors and LEDs to the native GPIO connector safely, and how to access them using simple Bash scripts. As you dive further in, you’ll learn how to build an input/output expansion board using the I2C interface and power supply, allowing the connection of the large number of sensors needed for a typical home security setup.

    In the later chapters of the book, we'll look at more sophisticated topics such as adding cameras, remotely accessing the system using your mobile phone, receiving intrusion alerts and images by e-mail, and more.

    By the end of the book, you will be well-versed with the use of Raspberry Pi to power a home-based security system that sends message alerts whenever it is triggered and will be able to build a truly sophisticated and modular home security system. You will also gain a good understanding of Raspberry Pi's ecosystem and be able to write the functions required for a security system.

    Style and approach

    This easy-to-follow guide comprises a series of projects, where every chapter introduces a new concept and at the end of the book, all these concepts are brought together to create an entire home security system. This book features clear diagrams and code every step of the way.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Building a Home Security System with Raspberry Pi
      1. Table of Contents
      2. Building a Home Security System with Raspberry Pi
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Setting Up Your Raspberry Pi
        1. Which flavor of Pi?
          1. Raspberry Pi Model A
          2. Raspberry Pi Model B
          3. Raspberry Pi Model B+ and Model 2
          4. Model comparison table
          5. So which one?
        2. Preparing the SD card
          1. Downloading the Raspbian image
          2. Using Microsoft Windows
          3. Using Linux
          4. Booting your Pi
          5. Expanding the file system
            1. Using the raspi-config utility
        3. Setting up your Pi
          1. Getting up to date
          2. Getting the right time
            1. fake-hwclock
            2. ntp
          3. Talking of security…
            1. What is this sudo thing anyway?
          4. Connecting via Wi-Fi
        4. Summary
      9. 2. Connecting Things to Your Pi with GPIO
        1. Prerequisites
        2. Say hello to the GPIO
          1. Digital I/O pins
          2. The I2C bus
          3. The SPI bus
          4. The UART serial bus
          5. USB ports
          6. Power connections
        3. Getting acquainted with the GPIO
          1. Let there be light
            1. Getting flashy…
          2. Adding a switch
            1. Pulling yourself together
            2. The detection script
        4. The most elaborate light switch in the world
          1. The illuminating script
        5. Summary
      10. 3. Extending Your Pi to Connect More Things
        1. Prerequisites
        2. The I2C bus
          1. Just 2 wires
          2. What's your address?
          3. There is a parallel universe
            1. Serial-to-parallel conversion
        3. Give me power
        4. Building an I2C expander
          1. The I2C port expander circuit
            1. Let's walk through the circuit
          2. Building your expansion board
        5. Using ready-made expansion boards
          1. Hobbytronics MCP23017 expander port kit
          2. PiFace Digital I/O expansion board
          3. Gertboard
        6. Summary
      11. 4. Adding a Magnetic Contact Sensor
        1. Prerequisites
        2. The working of magnetic contact sensors
        3. Setting up the I2C port expander
          1. Enabling the I2C Bus
          2. Installing the I2C tools package
          3. Finding our devices
          4. Setting up the port expander
        4. Connecting our magnetic contact sensor
        5. Monitoring the sensor
        6. Anti-tamper circuits
        7. Getting into the zone
        8. Summary
      12. 5. Adding a Passive Infrared Motion Sensor
        1. Prerequisites
        2. Passive infrared sensors explained
          1. Setting up your PIR sensor
        3. Give me power (again)
        4. Connecting our PIR motion sensor
        5. 12V alarm zone circuits
          1. Alarm circuit protection
          2. How it works
        6. Wireless PIR motion sensors
          1. 433-MHz wireless alarm systems
          2. Connecting a 433-MHz receiver
            1. The alternative approach (because we have no choice)
          3. The receiver wiring diagram
        7. Logging detection data
        8. Summary
      13. 6. Adding Cameras to Our Security System
        1. Prerequisites
        2. The Raspberry Pi camera module
          1. Connecting the camera module
          2. Setting up the camera module
            1. Testing the camera module
        3. Be a video star
          1. Caught on camera
        4. You have new mail
          1. Setting up the e-mail sender client
          2. Sending attachments
          3. Where was that taken?
        5. Night vision
          1. An illuminating experience
          2. The Elaborate light switch re-visited
          3. Is that a badger?
        6. Using USB cameras
          1. Installing the webcam
          2. Taking a snap
            1. Snap snap snap
        7. The multicamera setup
          1. The Slave driver
        8. Summary
      14. 7. Building a Web-Based Control Panel
        1. Installing the web server
          1. Testing the PHP5 installation
        2. Being in control
          1. Arming yourself
        3. The master configuration file
        4. Creating the web page
          1. The control panel HTML template
          2. Giving it some style
          3. Making it dynamic
            1. Getting a bit of help first
            2. The main PHP code
            3. I'm someone else
        5. Remote access to our control panel
          1. Setting up a dynamic DNS account
            1. The Raspberry Pi dynamic DNS client
          2. Setting up a static IP on your Raspberry Pi
          3. Port-forwarding
        6. Summary
      15. 8. A Miscellany of Things
        1. Arming and disarming the system
        2. Driving inductive loads
        3. Beyond intrusion
          1. A simple water detector
            1. How it works
          2. A simple temperature sensor
            1. How it works
          3. A carbon monoxide detector
        4. Remote administration for our Raspberry Pi
          1. Getting Webmin
            1. Updating the repository sources
            2. Importing the signing key
            3. Accessing Webmin locally
            4. Remotely accessing Webmin
        5. Summary
      16. 9. Putting It All Together
        1. Alarm system diagram
          1. Overview of the system elements
            1. A +12V power supply
            2. A +3.3V power supply
            3. The opto-isolator input module
            4. The port expander
            5. An arm/disarm switch
            6. Alarm outputs
        2. Designing the control scripts
        3. Building the control script
          1. Exploring the script code
            1. Declarations
            2. Updating config settings
            3. Setting up the GPIO
            4. Setting up the I2C port expander
            5. Decoding the zone inputs status
            6. Initialization
            7. The system monitoring loop
            8. Arming the system
            9. Monitoring the zones
            10. Entry delay
            11. Sounding the main alarm
            12. Disarming and resetting the system
            13. We're done (almost)…
        4. Automatically starting the system
        5. Preserving the SD card
          1. Creating a RAM-based file system
        6. Conclusion
          1. Tips for building systems
        7. Summary
      17. Index