How to guard your home with Raspberry Pi

Raspberry Pi

The Raspberry Pi is an impressive platform for prototyping projects of any scale. From a simple blinking LED to a quadcopter, anything is possible with a Raspberry Pi – all you need is a little imagination and some extra components.

One of the most interesting areas of practical use is sensing the world around us, and using the data gathered in all sorts of ways. The world is full of data just waiting to be recorded and manipulated – for example, weather stations come with many different sensors to measure temperature, wind speed, humidity and pressure.

All this data can be stored and manipulated by a savvy hacker to produce graphs and tables that can be imported into other applications or projects. And of all the sensors on the market, the cheapest and most simple is the humble PIR, which is present in so many parts of everyday life.

Raspberry Pi

PIR plans

Passive infrared sensors (PIR) are commonly used in devices such as triggers for burglar alarms in homes and offices. In fact, they are so cheap that they're found inside motion-activated air fresheners, which could be a ripe source of components for this project.

The PIR sensor works on the simple principle of sending a beam of infrared light into a room. If the beam remains unbroken – by which we mean there is no movement in the room – no action is taken.

But the second the beam is broken, a signal is sent to a device that's programmed to respond in a certain manner. These PIR sensors are very cheap – around £4 (about $6, AU$8.40) delivered on eBay – and they are also an excellent starter project because they require very little breadboarding or prototyping.

For our project, we will set up a PIR sensor to watch an area for any movement. Once movement is detected, it will trigger the code to complete a sequence of events that will capture a picture of the event and record a short 10-second video at a resolution of 640 pixels by 480 pixels.

The project will culminate with a text message being sent to our phone, alerting us to an intruder or other event. To explain how this project will work, we'll illustrate it using pseudocode, which is a way of explaining a programming sequence using easy-to-understand language. Here's how the project will work in pseudo code:

PIR sensor sends out a beam.

If the beam is broken.

Send a signal to our Raspberry Pi.

On receiving the signal, the Raspberry Pi will take a picture of the activity.

The Pi will then record 10 seconds of video.

After the picture is created, the Pi will attempt to send a text alerting us to the activity.

This text will contain a picture and video .

Once the text has been sent, the Pi will wait for 30 seconds before looping the process.

So where could you use this project? The most obvious answer would be home security but let's think of something nicer.

In the summer there are lots of plants growing and animals moving in the sunshine, so why not use your Raspberry Pi and this project to capture the joys of summer?

You could house this project in a weatherproof case and leave it outside to record animal life. In fact, a project similar to this was used to monitor the feeding patterns of birds caring for their offspring.

A sensor was placed near the nesting box, and this would record the comings and goings of the parent birds. This data was then linked to weather data for that area.

When comparing the data, it became clear that the natural food of birds – insects – were not as abundant when the weather was rainy or windy. This meant the offspring were not being fed as often.

Alert! Alert! In this project, we're choosing to alert the user via a text message, because no matter what type of phone you have, and what type of signal you receive, a text message is more reliable as a method of delivery than an email or tweet, which rely on 3G or Wi-Fi coverage to receive data.

This project can be built upon to include other methods of delivering the alert – in fact, you can send more than one alert from the project.

To send an email, you can use the smtplib, and we found a great how-to. You can also send a tweet from Python using the tweepy library.

To do this you will need to create an application via https://dev.twitter.com. Once you have completed this part of the process, you can import the API key into tweepy and use it to send and receive tweets.

You can read more about tweepy via its website. The pictures and video that are captured in this project are stored on our Raspberry Pi for later retrieval via any means that is convenient.

Latest in Raspberry Pi
white keyboard PC with mouse and book
The Raspberry Pi 500 is a state-of-the-art keyboard PC...just like the Tandy 1000 in the 1980s
Raspberry Pi strapped to a satellite takes stunning picture of Earth
Kali Linux on Pi 4
Raspberry Pi 4 gets Kali Linux, a distro aimed at ethical hackers
Worried about Alexa spying on you? This Raspberry Pi smart speaker for kids puts privacy first
How to install Ubuntu on the Raspberry Pi
New Raspberry Pi 3 Model A+ is somehow even smaller and cheaper
Latest in How Tos
Trinity Rodman #2 of the Washington Spirit crosses the ball during a game between Bay FC and Washington Spirit at Audi Field on November 10, 2024 in Washington, DC.
National Women's Soccer League 2025: How to watch NWSL games live from anywhere
tiktok
How to edit TikTok videos
Irish boxer TJ Doheny receives an undercard bout, ahead of the WBO super welterweight world title fight in March, 2023
Ball vs Doheny live stream: how to watch the boxing action from anywhere
 Facebook social media app logo on log-in, sign-up registration page
How to delete all your Facebook posts
Bruno Guimaraes of Newcastle United during the Carabao Cup Semi Final Second Leg match in February 2025
Liverpool vs Newcastle live stream: how to watch Carabao Cup final 2025 online
Max Verstappen of Red Bull in testing for the 2025 season in Bahrain
Australian Grand Prix 2025: How to watch F1 First Practice race online from anywhere