Surveillance cameras are big business and way too expensive when you want to buy one from a reputable brand. Here's an example: Logitech Alert 750e Outdoor Master Security Camera System with Night Vision currently sells at US$999.
In this post I'll show you how to build your own surveillance camera for fun and for way cheaper. Let's get started.
For this, you'll need:
- a Raspberry Pi 2
- a 16GB micro SD card for the Raspberry software
- your favorite USB webcam
- an Ethernet cable and a router with at least one RJ-45 free LAN slot
- And of course a computer with an SD card reader
- The first step is to download and install the operating system for the Raspberry Pi. While Raspbian the official Linux OS for the Raspberry Pi is an option, I didn't like it that much as there are way too many things that get automatically installed on it. I decided to go the leanway by installing Debian Jessie instead. Download it from here http://sjoerd.luon.net/posts/2015/02/debian-jessie-on-rpi2/ (latest image at https://images.collabora.co.uk/rpi2/jessie-rpi2-20150705.img.gz) then extract the gzip archive and use Win32DiskImager to write the downloaded image to the SD card.
- Eject the SD card and insert it into the Raspberry Pi, then power the Raspberry using the micro-USB slot. Also connect the Raspberry to your router using Ethernet cable.
- The Raspberry Pi will automatically boot on the SD card pre-installed image, establish an network connection and the SSH deamon will be listening for us. But first we need to find its IP address. For that we can use nmap which is a network scanner. Download and install nmap then open a command prompt .
- In the command prompt type ipconfig. This will provide valuable info about our local network. As you can see, my IP address is 192.168.88.47.
- Now we scan the network using nmap -p22 192.168.88.2-192.168.88.254 (replace 88 with your local flavor). What this does is to scan the whole local network (except for the gateway) for devices listening on port 22 which is the SSH default port.
- In this example, you can see that 6 devices are present (my computer included) and among them are 4 Raspberry Pi. Now that we have its IP address we can establish a connection using SSH. Probably the best SSH option on Windows is Putty. Download and install it.
- Start Putty and enter the IP address of the Raspberry Pi under Host name then click open
- The default login is root/debian
- Start by changing the root password using the passwd command
- Update the system: apt-get update then apt-get upgrade
- Update the Raspberry date, time and timezone.
- Install sudo and add a user account: apt-get install sudo then adduser youruser
- Make the new user a system administrator: sudo adduser cat sudo
- Now that we created the user account, let's disconnect from this session and reconnect but with the user account this time. Now let's remove the possibility to login as root. sudo passwd -l rootIf you want to learn more about why it's important to disable root login...
- Add USB utilities: sudo apt-get install usbutils
- Check that your camera is detected: lsusb
- Install the camera software: sudo apt-get install motion
- Backup the motion configuration file: sudo cp /etc/motion/motion.conf /etc/motion/motion.conf.bak
- Edit the motion configuration file: sudo nano /etc/motion/motion.conf
- Here's the list of changes I made on mine
height 960framerate 5quality 95
Save the file CTRL + O and exit nano CTRL + X
- Create dir /var/motion/ : sudo mkdir /var/motion and assign ownership to motion: sudo chown motion:motion /var/motion
- Start the motion deamon when the system starts: sudo nano /etc/default/motion and set daemon to yes
- Test if everything works accordingly: sudo service motion restart
- After a few seconds check if any content was generated in the motion target dir: ls /var/motion/ -l
- And even better, you can now also access the live stream server at http://192.168.88.26:8081 . Well that's it! If you have any issues or problems, just report them in the comments section.
- Update: if you notice after reboot that no photos are being captured, here's how to troubleshoot: sudo service motion status. This will show the status of the motion service and will show any errors that could have occurred. It's usually permission issues on the motion config file or the motion log file which can be fixed with chown and chmod.