How to make your own LizardCam!

I’ve had a lizard cam of one sort or another running for a few years now. My current iteration is inexpensive (about $125 using my links below) and easy to set up, so I’d like to write a tutorial on you can set up your own.

Materials:

  1. A web cam, like this one (link). I like this one because there’s a little hole in the fixture that allows you to nail it to walls.
  2. A Raspberry Pi (link). A tiny, inexpensive computer! I recommend a Raspberry Pi 3 (link), since it comes with built in Wifi, so you can position it anywhere in your home.
  3. A 64 GB mini SD card. This’ll be your Raspberry Pi’s hard drive. Quality matters here; a cheapo micro SD card will cause your Raspberry Pi to crash after a few days/weeks. I recommend going with Samsung (link).
  4. Raspbian, your operating system for the Rasberry Pi. You can download it here (link).
  5. An internet connection!

Instructions:

Install Raspbian

First, get Raspbian installed onto your SD card and start up the Raspberry Pi. I used the following instructions to help me get started. This should work for any savvy Windows user and should have you nearly ready to set up the cam.

NOTE: The instructions on copying the Raspbian image onto the SD card will vary depending on whether you are using Windows, Mac, or Linux.

The instructions in the video fit Windows perfectly.

Mac (link)

Linux (link)

Highlights from the video:

  1. Obtain the things that you need.
  2. Download the Raspbian image and copy it to the SD card using the appropriate method for your system.
  3. Get the system up and running, update software, and ensure a healthy configuration.

NOTE: Two more things that you should do before moving to setting up your cam is resizing your root filesystem to fill up your entire SD card and setting the correct timezone for your Raspberry Pi.

These instructions (link) should help you with adjusting the root fs size. This way, your operating system can work with a full 64 G of disk space instead of the default 4 G.

These instructions (link) should help you with adjusting the timezone for your Raspberry Pi.

Setting up the Cam using Motion

Setting up the camera itself is relatively easy. By this point, your Raspberry Pi should be powered on and you should have a command line in front of you (either by logging into the terminal directly or by starting up a terminal in the OS interface). Run the following command to install ‘Motion,’ the program that powers the web cam.

sudo apt-get install motion -y

Wait for the installation to complete.

When the installation has completed, review Motion’s configuration file at /etc/motion/motion.conf. You can use this using the ‘nano’ command on the command line or a file editor in the OS interface.

nano /etc/motion/motion.conf

You will see a default configuration file in front of you. Most of the configuration items here are fine and do not need to be modified. I do have a few items that I recommend changing, though.

Ensure that you have the right frame size set for your web cam. I use the below settings.

# Image width (pixels). Valid range: Camera dependent, default: 352
width 640

# Image height (pixels). Valid range: Camera dependent, default: 288
height 480

Make sure that you have an appropriate frame rate set. I use 20, since that lowers the network bandwidth and ensures better quality to users geographically far away from me.

# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 20

# Maximum framerate for stream streams (default: 1)
stream_maxrate 15

Ensure that the ‘stream_port’ setting is changed to ’80’ from ‘0,’ and also set the ‘stream_localhost’ setting to off. This way you can actually see your over the internet!

# The mini-http server listens to this port for requests (default: 0 = disabled)
stream_port 80

# Restrict stream connections to localhost only (default: on)
stream_localhost off

There may be some other configurations that I’m missing, and there may be some other tweaks that you may want to make, but if you want to have a working configuration with few questions asked, you can find my current configuration here (PasteBin.com link).

Once you’ve done all that, give things a test by plugging your webcam into the Raspberry Pi and starting up Motion. You can start up Motion using the following command.

sudo /usr/bin/motion -c /etc/motion/motion.conf

All being well, you should see the light on your webcam light up, which indicates that Motion is capturing frames and. Next, test to see if you can actually see the stream by going to your Raspberry Pi’s local area network address in your browser and seeing if it loads the stream. You can find out the local area network address by running this command.

ifconfig | grep 192

When done testing, run the following command to turn Motion off.

sudo /bin/pidof motion | sudo xargs kill -9

Finishing Touches

The last things to do are setting up a schedule by which your cam runs (if that’s something that you want), positioning your cam and Raspberry Pi appropriately in your home, and making sure that the outside world can reach it by setting up pinholes through your home router.

 

Using Cron Jobs to Schedule your Cam

Let’s talk about scheduling the cam first. In Linux, scheduling is done using something called ‘cron jobs (link).’ Here are the cron jobs I use and an explanation of how they work and how to I install them.

#lizard cam start
0,20,40 13,14,15,16,17,18 * * * root /usr/bin/motion -c /etc/motion/motion.conf

#lizard cam stop
19,39,59 * * * * root /bin/sleep 55; /bin/pidof motion | /usr/bin/xargs /bin/kill -9

I install the cron jobs by creating a file in /etc/cron.d/ called ‘motion’, and then copying the above contents into this file. Here’s what they do.

  1. At the 0th, 20th, and 40th minute (0,20,40) of the 13th, 14th, 15th, 16th, 17th, and 18th hours (13,14,15,16,17,18) every day of the month (*) of every month (*) and every day of the week (*), start the web cam as the root user (root /usr/bin/motion -c /etc/motion/motion.conf).
  2. At the 19th, 39th, and 59th (19,39,59) minute of every hour (*) of every day of the month (*) of every month (*) and every day of the week (*), wait 55 seconds from the start of the minute and then stop the Motion process if there are any running (root /bin/sleep 55; /bin/pidof motion | /usr/bin/xargs /bin/kill -9).

You can modify the cron jobs to fit an appropriate schedule. Just make sure that you are setting it according to the Pi’s system timezone, and not whatever your local timezone actually is. If you adjusted it during the setup above, then this shouldn’t be a concern.

 

Always on Web Cam

If you want your web came to always be on when you start up your Raspberry Pi, then you will want to do the following.

Open up the /etc/rc.local file (link) with a text editor either on the command line or in the OS interface.

sudo nano /etc/rc.local

Put the following command into the rc.local file just above the “exit 0” line.

/usr/bin/motion -c /etc/motion/motion.conf

All being well, the next time that you plug in your Raspberry Pi your webcam should start immediately.

 

Positioning

Assuming that you’ve made it this far without issues, you can unplug your Raspberry Pi from everything, position it in an appropriate spot in the house where you can reach both an internet cable, power, and the spot where you want your web cam, and then plug everything in!

 

Pinholes through your Router

If you want the outside world to be able to see your cam, then you will need to make sure that incoming traffic from the internet can pass through your router to the Raspberry Pi. Every router is a bit different, so I can’t provide detailed instructions here.

However, the basic gist of it will be the same across all platforms. Make sure that outside traffic hitting your public IP address on port 80 can reach your Raspberry Pi’s LAN address on port 80 as well. Once that’s done, then you should be able to go to your public IP address and see your web cam!

 

Questions and Problems?

If you’re having any issues with these instructions, then please feel free to reach out to me on Twitter. I’ll be glad to help out in any way that I can!