How to build a Raspberry Pi security camera
Build your own cut-price surveillance equipment
The tiny powerhouse that is the Raspberry Pi can be built into almost any project, and in this case can be used as the starting point for a security camera system that will rival many commercial offerings - given minimal DIY hackery.
As ever with the Raspberry Pi and associated projects, there are plenty of variations on making a 'security camera', beginning with the hardware choices you have to hand, or the final system if you're building a dedicated setup, as opposed to tinkering for fun.
Choosing your hardware
Aside from the choices of Pi platform, which will dictate size, Wi-Fi complexity and cost, there is also the obvious requirement for a camera module. While any USB webcam will probably do the job, it's worth splashing out a little to get an official camera board that definitely will, and also avoids a host of potential troubleshooting issues.
There are two official options for this: the Raspberry Pi Camera v2 and the Raspberry Pi NoIR Camera v2, the latter being specifically designed for low-light applications. They both feature an 8 megapixel Sony IMX219 image sensor, which supports 1080p video at 30fps, 720p at 60 and 640x480p at 90fps. They connect direct to the Pi via a dedicated ribbon socket, and are supported natively in Raspbian. In short, one of these is your best choice, depending on whether you're planning mostly daytime video, or a significant amount of night/twilight work.
If you're planning a security camera system with dedicated hardware, then the cheaper Pi Zero W paired with one of the many night-vision kit cameras is worth considering, as this option keeps hardware costs, size and unwanted additional components to a minimum. Note, though, that the Pi Camera v2 needs an additional adaptor to work with the Pi Zero range.
Aside from your choice of Pi and camera combo, you'll need the usual USB power supply, an 8GB minimum SD/Micro SD card with Raspbian installed and either a monitor/keyboard/mouse or remote access enabled. Although you'll be able to get this project up and running without a case, you'll need to buy or build a suitable item depending on where you plan to monitor - weatherproof options are usually a good idea unless they''ll be living exclusively indoors.
Also bear in mind that motion-based camera systems can generate large volumes of video, which will require large amounts of either local or network storage if you want to view it later. This project can accommodate either, depending on your needs.
Once you've connected everything up - and carefully clipped the camera board in place - you're ready for the software bit. There are two simple routes to go down here - either install Motion and tweak it to suit, or go for an all-in-one option, like MotionEye, a Linux distribution that turns a single-board computer into a video surveillance system. The OS is based on BuildRoot and uses Motion as a backend and MotionEye for the frontend.
We'll go with MotionEye here, as it rounds off some of the corners without adding much in terms of complexity.
Downloading and writing MotionEye image to disk
First, download the latest version of MotionEye for your device, extract the image file from the archive and write it to your SD card. You can use Etcher.io on Windows, or in Linux there is a writeimage.sh script that will do everything for you.
Just run the script as follows (replacing the arguments with appropriate values):./writeimage.sh -d /dev/mmcblk0 -i "/path/to/motioneyeos.img"
Note that you'll need to specify the device path to the disk and not to some partition (for example /dev/mmcblk0 instead of /dev/mmcblk0p1).
You can preconfigure a wireless network connection - or a static IP if you'd rather not use DCHP - with the following command. Just use this command for Wi-Fi:./writeimage.sh -d /dev/mmcblk0 -i "/path/to/motioneyeos.img" -n 'yournet:yourkey'
...and this command for a static IP:./writeimage.sh -d /dev/mmcblk0 -i "/path/to/motioneyeos.img" -s "192.168.1.101/24:192.168.1.1:126.96.36.199"
Boot and setup
This complete, you're ready to boot the image. This will take a few minutes as the system auto-configures. Your motionEyeOS needs an IP address before you can communicate with it so you'll have to use the ethernet connection with DHCP enabled, unless you have preconfigured a static IP address.
As soon as your motionEyeOS setup is complete, it will listen on port 80 and present you with a web user interface - simply enter the IP address of your board in the address bar of your browser. Use your router to display devices on your home network, or use a network scanner to hunt for a device called "meye-".
Once found, you'll be able to click on the user icon on the upper-left side of the page to switch user to administrator. Use admin with no password when asked for credentials - the user setting is for remote monitoring, the admin for changing settings.
MotionEyeOS has a broad range of settings to play with, but the first thing you'll want to do is set up passwords for both admin and user, set the timezone and enable wireless. After that, choose the desired resolution, frame rate, and other details of your video feed, and configure file storage if you want your pictures and movies saved on a network or USB drive.
You'll be able to monitor your camera remotely (including on a smartphone) by visiting the relevant IP, inputting your 'user' login, and then using the web interface. The interface also allows you to browse, preview and download videos and images from each connected camera by using the media browser window which opens by clicking on the pictures or movies buttons.
This project gives you the beginning of a great security camera system which can scale up to monitor almost any situation, and is far more flexible than most comparable-price commercial systems. In addition, the Pi and Camera board can be the basis for a wide range of other projects too, including wildlife cameras or timelapse photography.
Thanks to Calin Crisan for his MotionEyeOS
The IT Pro guide to Windows 10 migration
Everything you need to know for a successful transitionDownload now
Managing security risk and compliance in a challenging landscape
How key technology partners grow with your organisationDownload now
Software-defined storage for dummies
Control storage costs, eliminate storage bottlenecks and solve storage management challengesDownload now
6 best practices for escaping ransomware
A complete guide to tackling ransomware attacksDownload now