Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Building a Home Security System with Raspberry Pi
Building a Home Security System with Raspberry Pi

Building a Home Security System with Raspberry Pi: Build your own sophisticated modular home security system using the popular Raspberry Pi board

Arrow left icon
Profile Icon Poole
Arrow right icon
S$29.99 S$42.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (3 Ratings)
eBook Dec 2015 190 pages 1st Edition
eBook
S$29.99 S$42.99
Paperback
S$52.99
Subscription
Free Trial
Arrow left icon
Profile Icon Poole
Arrow right icon
S$29.99 S$42.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (3 Ratings)
eBook Dec 2015 190 pages 1st Edition
eBook
S$29.99 S$42.99
Paperback
S$52.99
Subscription
Free Trial
eBook
S$29.99 S$42.99
Paperback
S$52.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Building a Home Security System with Raspberry Pi

Chapter 2. Connecting Things to Your Pi with GPIO

The Raspberry Pi has lots of ways to connect things to it, such as plugging things into the USB ports, connecting devices to the on-board camera and display ports, and connecting things to the various interfaces that make up the GPIO connector. As part of our home security project, we'll be focusing mainly on connecting things to the GPIO connector.

In this chapter, we will cover the following topics:

  • Examining the GPIO connector and what each of the pins does
  • Learning about the I2C and SPI buses that will be used in later chapters
  • Connecting an LED and a switch safely to the data pins, and accessing these data pins using simple scripts
  • Understanding the USB ports and their limitations

Prerequisites

Along with your Raspberry Pi, you'll need the following parts for the projects in this chapter:

  • A breadboard
  • An LED
  • A 220 ohm resistor (red, red, black)
  • A 10K ohm resistor (brown, black, orange)
  • A pushbutton or toggle switch
  • A hook-up wire:
    Prerequisites

    Our little collection of parts

Say hello to the GPIO

The GPIO connector is the large group of pins on the edge of your Raspberry Pi board. On earlier models, there were 26 pins that made up this connector. But, ever since the Model B+, there have been 40 pins, although the first 26 pins are identical to the previous models, and it's these 26 pins we'll be working with. You won't need to worry about the rest of the pins.

Essentially, the GPIO connector provides access to following:

  • Power supplies
  • Digital I/O pins
  • I2C bus
  • SPI bus
  • UART Serial bus

Some of the pins on the GPIO have more than one purpose, depending on how they are programmed. The following diagram is a reference guide to all of the pins on the GPIO. The GPIO numbers on the yellow labels relate directly to those on the Broadcom chip, and are numbers generally used within the scripts.

Say hello to the GPIO

Digital I/O pins

The GPIO has 8 digital input/output pins available for use. These can be used to switch things on and off (in output mode), and also to detect when external...

Getting acquainted with the GPIO

Before we embark on connecting lots of things to our Pi board, it might be a good idea to just get acquainted with the GPIO through a couple of simple projects that will help us understand how to interact with the digital I/O pins using shell scripts.

Let there be light

This simple little project shows how to connect a GPIO output to an LED, and switch it on and off using shell commands.

The following diagram shows how to connect up the circuit using a breadboard:

Let there be light

Note

The pretty diagram that you just saw was produced using a free software tool from fritzing, which is an open-source hardware initiative to make electronics accessible as creative material for anyone. Download it from fritzing.org.

The LED anode (the positive side) is connected to the D0 digital I/O (pin 11 of the connector or GPIO17). When this pin is switched on, it will provide a 3.3V supply to the LED.

The LED is connected to the Ground pin via a 220R resistor on the cathode (negative side). The...

The most elaborate light switch in the world

By combining the two little projects earlier, we can now create a system that will do something useful when the pushbutton switch is pushed—for example, switching on the LED that we also have connected. Granted, we could just connect the LED directly to the switch and a battery, but not only would that be boring, it would defeat the point of what we're trying to do, which is programmatically sensing and controlling things.

Here's the breadboard layout for our elaborate light switch:

The most elaborate light switch in the world

And here's the circuit diagram:

The most elaborate light switch in the world

The illuminating script

Our full Bash script for our elaborate light switch is demonstrated next. This will loop endlessly, detecting the state of the switch GPIO pin, and will turn on the LED GPIO pin when the switch is pushed.

The code listing for light-switch.sh is as follows:

#!/bin/bash

#set up the LED GPIO pin
sudo echo 17 > /sys/class/gpio/export
sudo echo out > /sys/class/gpio/gpio17/direction

#set up...

Summary

In this chapter, we introduced various ways to connect your Raspberry Pi to the outside world by looking at the various interfaces available on the GPIO. We've understood how to connect things to the digital pins on your Raspberry Pi's GPIO connector, and control and read them using simple Bash scripts. In particular, we've safely and properly connected a switch to a digital input pin, which will form the foundation for our home security detection circuits.

In the next chapter, we'll look at ways to expand the number of things we can connect to our Raspberry Pi, overcoming the limitation of having just the 8 digital pins available to us on the GPIO by tapping into other interfaces on the GPIO and building our own input/output expansion board.

Left arrow icon Right arrow icon

Key benefits

  • • 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

Description

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.

Who is this book 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 28, 2015
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781785283062
Category :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 28, 2015
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781785283062
Category :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 119.98
BeagleBone Home Automation Blueprints
S$66.99
Building a Home Security System with Raspberry Pi
S$52.99
Total S$ 119.98 Stars icon

Table of Contents

10 Chapters
1. Setting Up Your Raspberry Pi Chevron down icon Chevron up icon
2. Connecting Things to Your Pi with GPIO Chevron down icon Chevron up icon
3. Extending Your Pi to Connect More Things Chevron down icon Chevron up icon
4. Adding a Magnetic Contact Sensor Chevron down icon Chevron up icon
5. Adding a Passive Infrared Motion Sensor Chevron down icon Chevron up icon
6. Adding Cameras to Our Security System Chevron down icon Chevron up icon
7. Building a Web-Based Control Panel Chevron down icon Chevron up icon
8. A Miscellany of Things Chevron down icon Chevron up icon
9. Putting It All Together Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(3 Ratings)
5 star 33.3%
4 star 0%
3 star 33.3%
2 star 0%
1 star 33.3%
Amazon Customer Jan 19, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book helps you transforming your Raspberry Pi into a surveillance system with ease. Different topics in this book provide you with useful information which are relevant in the surveillance industry nowadays.The author provides you with simple and practical examples. As a Technical reviewer of this book I strongly recommend this to anyone who's interested in surveillance and the Raspberry Pi. It gives a deep understanding of how surveillance works.
Amazon Verified review Amazon
Brennan Johnson Jan 01, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I found this book disappointing in general, but it's not all bad.Pros:- It clearly leads you through the initial steps of getting a raspberry pi up and running from scratch. I had never used a pi before, and I was easily able to follow the instructions to get the operating system installed and to get everything configured. It is awesome that this can lead a complete beginner through what I'd consider an intimidating process.- It has examples that include all of the steps and code necessary to make it work. I haven't tried everything in the book, but all of the examples I tried worked.- The examples it provides include most of the basic things you'd hope for. It tells you how you can hook up a motion sensor, take a picture when motion is detected, and send the picture to yourself in an email. That's pretty cool.Cons:- The examples tell you only what you need to know to make them work. There's not much background information, so you're left pretty ignorant to exactly what is happening.- There's not enough detail in general. This book is trying to be as simple as possible, I realize, but it's not nearly technical enough for me. Anyone who thinks like an engineer is going to be disappointed at the lack of background explanation of how anything works.- The book sticks with bash scripting to run commands. I found bash to be an absolutely miserable language to work with and would have much preferred python. One huge reason why python would potentially be better is that most other people using pi seem to be using python. If you look around online for how to do additional things with the pi, you're going to come across a bunch of python examples. Since this book doesn't even mention python, you're not going to be in a position to apply those examples without learning some basic python stuff first. It says something about other programming languages being out of scope. I'd argue that bash is a language too, so making me type out bash scripts isn't much different than python scripts. There might very well be a reason why bash is better for the purpose of a home security system, but it doesn't explain how. Bash is not user friendly and seems ridiculously archaic.- The book gives practically no explanation of how bash works, so you're not going to able to do anything beyond the examples without additional research elsewhere. It doesn't explain bash syntax, and since bash scripts are behind much of the functionality of the systems it is creating, I find that to be a huge problem.- The book gives very little explanation for why it does things the way it does. For example, why use the console instead of the UI? Why use bash instead of phython? Why use Putty? Why use the hardware it chose? What other options do I have? I would assume that the book is leading me in the right direction, but it generally leaves me ignorant to my other options and leaves me with little confidence in what I'm doing. Also, it uses all kinds of third party software that you download...that seems like a huge security threat. It would be nice if it could explain why it chose these things so that I could have more confidence that this is a good and secure setup.- It doesn't include some more advanced things that seem obvious. For example, is there a way to live-stream my camera output? That would be awesome, but I'm not seeing that in there.- Maybe this isn't a fair con, but it's something to realize: some of the examples in the book are expensive to try. They will require hardware that can cost $50+ a piece. I haven't bothered to calculate it, but if you bought everything the book used, you will have spent at least a few hundred dollars.As frustrated as I am at the lack of content, I still got a lot out of this book. It was a very good intro to the raspberry pi, and I was able to get a rudimentary security system up and running with it. I think you could end up with a pretty decent system if you followed all the examples.
Amazon Verified review Amazon
Ranjan S. Dec 31, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Does not meet expectation
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.