Skip to content

How to build your own surveillance camera

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:

  1. a Raspberry Pi 2
  2. a 16GB micro SD card for the Raspberry software
  3. your favorite USB webcam
  4. an Ethernet cable and a router with at least one RJ-45 free LAN slot
  5. And of course a computer with an SD card reader

raspberry-pi-setupsd-card

  • 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 https://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.win32-disk-imager
  • 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.ipconfig-result
  • 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.nmap-results
  • 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 openputty-connect
  • The default login is root/debianlogin-as-root
  • Start by changing the root password using the passwd commandpasswd
  • Update the system: apt-get update then apt-get upgradeapt-get-update
  • Update the Raspberry date, time and timezone.
    1. apt-get install ntpdate
    2. ntpdate pool.ntp.orgntpdate
    3. cp /usr/share/zoneinfo/Europe/Riga /etc/localtime to set the time zone (adjust to your flavor)set-timezone
  • Install sudo and add a user account: apt-get install sudo then adduser yourusersudo-adduser
  • Make the new user a system administrator: sudo adduser cat sudosudo-adduser-2
  • 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 rootremove-root-loginIf 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 detect-usb-camera
  • Install the camera software: sudo apt-get install motioninstall-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
    logfile /var/motion/motion.log
    width 1280
    height 960framerate 5quality 95

    #sdl_threadnr 0

    snapshot_interval 360

    target_dir /var/motion

    snapshot_filename snapshot-%Y-%m-%d_%H%M%S-%v
    picture_filename motion-%Y-%m-%d_%H%M%S-%v-%q-%v
    movie_filename movie-%Y-%m-%d_%H%M%S-%v
    timelapse_filename timelapse-%Y-%m-%d
    stream_quality 95
    stream_motion on
    stream_localhost off

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/motionmotion-dir
  • 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/ -lmotion-test
  • And even better, you can now also access the live stream server at https://192.168.88.26:8081 . Well that's it! If you have any issues or problems, just report them in the comments section.live-stream
  • 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.

3 thoughts on “How to build your own surveillance camera

  1. jules

    It works! Thanks for an easy set up using latest Raspbian Jessie and latest Motion (3.2.12 git)
    The previous Wheezy set up I had used last year (2015) does not now work.

    I have one comment, no probs seeing location of jpg pics at 'ls /var/motion/ -l'
    I update snaps every 15 mins. I want to host these on apache2 server, but have probs getting this sorted. Again, apache2 has been updated. You wait a long time for a webcam update, then 3 come along together!
    I have installed apache2 and can see the default apache2 page, "it works," but can't get it to host the jpg pics from motion file.
    Thanks for any ideas

    1. Octopus

      Hi Jules, glad it worked for you. As to the small problem, I think you should look first into the live stream server settings. Please note that the live stream server and hosting the images on a website is not the same thing. Try editing your apache2 default html file and add code to link to your capture image if you want to go this way.

  2. jules

    Hi,
    Here is the part I am not sure about.....
    "Try editing your apache2 default html file and add code to link to your capture image."
    How do I do that? Maybe just a quick file move using mv, (my images files into apache html file) but not sure.
    Any help would be very useful. My motion set up is working well, but can't see the pics.

Comments are closed.