Raspberry pi model B

A system, which detects intruders on your property by sensing motion with infrared sensors, records video logs and sends SMS alerts to owner. Logs have a backup on a remote server. Uninterruptable power supply is also used.



This article is about how I’ve built a home security system based on Raspberry Pi microcontroller. It uses infrared motion sensors to detect intruders motion when security is enabled, a camera, an interface block and a WIFI connection to pass logs to a remote server, of course.  There are also future plans to add a weather station, gas and water leakage detectors, which will allow to prevent an explosion or a flood, which could cause a lot of trouble to your apartment.

Raspberry pi model B



First of all, it is understood that any security system must be “burglar proof”. It means that it should contain a backup battery in case  the electricity is down, a remote storage to keep all of the logs, video data and other stuff away from the secured household. Another task is to keep the connection with the “outer world” up in any circumstances.

Second of all, the system needs some response time before it will possibly be mechanicaly destroyed by the unwanted guest. Periphereal parts such as sensors or cameras can’t be totaly invisible, but the most important part is the main block as it is responsible for notifying owners about the happening situation. That’s why the main processor unit must be hidden properly.

The owner must be immediately notified when something goes wrong at home. The solution was using SMS messaging as it seemed the most instant way of notification.
How it works?

The main processor unit is the Raspberry Pi Model B.
It is connected via an 220v – 5v power adapter to an uninterruptable power supply.   As many of other components also use 5V input it was necessary to use a power adapter that can easily connect mulitple lines ( I’ll talk about it later). The local WIFI router is also connected to the UPS.

There are infrared motion sensors installed in all rooms.
As motion is detected video cameras start taking photos and uploading them to the remote server. If the correct passcode is not entered in 30 seconds the alarm goes off and an SMS is sent to owner. There is also a SOS button, which creates a similar alert on press ( even if the alarm is disabled ). This can be used to notify, for example, members of your family if you are in danger.

The owner can further check logs and photos on the remote server(it can even be a simple website on a free web hosting).

Lets take a first look at the main components:Total


Power supply

Raspberry Pi requires 5V input with at least 1A current to work properly. Sensors designed to work with such microcontrollers  are usually also 5V powered, as well as all USB peripherial devices. Some reccomendations about a proper RPI power supply can be found here.

I used a chinese  5V 10A  power adapter  available on ebay.com for approximately 7-10$ each. poweradapterIt has no microusb output, however it was pretty easy to simply attach the standard USB power line  (1 and 4 pins wires on photo bellow) to the power supply. 700px-USB.svg

Using a power adapter with a standard two pin output helps us to further connect all of the sensors to it.



I have used standard arduino/raspberry pi PIR motion sensors. You can buy them at ebay.com for approximately 1.5-3$ each.  These sensors have  a 3-pin interface (5V power, GND, 3.3V output). There are two adjustment knobs – one for sensitivity, other determines the time during which the output stays HIGH after motion (XS, XT labels).  You can find out more information about these adjustments here, but after some time was spent on testing, I came to a conclusion that the best adjustment is as on the photo below:

PIR motion sensor: optimal adjustment

The easiest way to have the sensors wired at your home/apartment is using the space behind plinths and door jambs. All you need is a 5V power line from the power adapter and a single wire for each sensor connected directly to Raspberrys GPIO port.

Do not try to supply power directly from Raspberrys 5V GPIO pins. The maximum current available on the board will not make your wiring work.

It is also nice to install sensors with LEDs. It makes testing easier and possibly will scare the burglar to death =) Don’t forget to use a   ~100 Ohm resistor together with the LED, otherwise  big current will burn it out really fast.

As you can see, the sensors are installed right above the doors in each room.  It is much more simple than putting them on walls that includes causing damage to your apartments finish.

Raspberry pi gpio bus


To take awesome pictures of unwanted guests I decided to use a popular Logitech C280 web camera. This one was already tested to work with RPI  at that time, besides the picture quality is fine.

The cameras start filming if motion is detected by one of the PIR sensors. It could have been much easier to use motion detection performed by the camera itself (there are various packages for motion detection  on the web), but in case of using many cameras this task could be to heavy for the RPI, besides camera based motion detection is not really stable and reliable in the dark.


Cameras can be connected with a USB extension cable (5m length in my case). The only problem was the USB current. It was too small to power the camera on a pretty long extension cable. The solution was to split the cable. The power line (+5V, GND) was connected directly to the power supply, the other two data cables were connected to the RPI.

To read incoming data from the camera I used the mjpg-streamer unix library. There is a short tutorial about using mjpg-stramer on Raspberry Pi written by Miguel Grinberg.



To enable the security system or to disable it by entering the right passcode a LOFREE  MT-100 block was used. It costs around 15$ and can be found on ebay.com.  It can use both wired and wireless modes, but I decided to connect it with it’s usb bluetooth dongle.
This allows to locate it wherever you want and it makes harder to find the main unit.




The hidden speakers are used for multiple purposes. The first one is the alarm syren, the second – by text to speech messages you can be informed about intruders, or any occured system error as well as the wrong entered password. There are various sites, that allow you to create a sound file for a given text.

Uninterruptable power supply

All of the related components are connected to the UPS.
It means that the internet connection, the security system itself will be up even when the electricity is down. Using a UPS is quite an expensive solution, but I had an unused one. The other option is to use a battery bank (one of those, which are used as a backup for mobile phones, laptops). But in this case you will need to adapt input of all devices to the battery voltage.