Raspberry Pi Spycam (SpyPi)

Need a nanny cam? Worried about your dogs? Wanna catch your Amazon package thief? I don’t personally care what you use a spycam for. I’m a guy with too much free time and not enough money to fill that free time. I build stuff. You build stuff. Everybody’s happy. Grab a drink and let’s go.

HINT: Think this version is too bulky? Keep in mind the only part that actually needs to be exposed is the lens of the camera. Everything else can be hidden. Still too big? Try it with a Raspberry Pi Zero W instead of a Raspberry Pi 3 and omit the project box, external storage, and extended cables. Looking for something a little more mobile? See ShoePi.

Coming Soon: An update to allow the lens of the camera to be separate from the PCB, which will allow the lens to be hidden in more places and be less visible. It will also allow better cable routing options when the bulk of the hardware can be hidden in a project box away from the camera. Stay tuned.


SpyPi's purpose is to be a stationary spy camera. It follows the "set it and forget it" doctrine that works best with spy cameras and is meant to be robust and respond to failures.

This system will be comprised of 2-3 main parts:

  1. The Raspberry Pi (with optional faster and extra storage described below)

  2. The sweet, succulent code

  3. The mobile power station (optional)

The main idea is, you set the SpyPi up in an inconspicuous place and you SSH in and start the motion detection script. When the camera module detects motion, it will start recording video. After an amount of time that you specify, it will launch the motion detection again, and the cycle repeats until you stop it. If any of that doesn’t make sense right now, don’t worry. We’ll go more in depth below.


Protip: Some of these are affiliate links to Amazon product pages, wink wink (buy my shit).


Before we start, quick announcement:

If you catch anything interesting on one of my SpyPi’s or if you find an interesting use for one and you’re willing to share, I’d love to see/hear about it. Feel free to send anything to

Step 1: Burn the latest Raspbian OS to your micro SD card, make sure SSH is enabled, and boot the pi (tutorial here).
Note: This project works fine on both Raspbian Buster and Raspbian Stretch.

Step 2 (only if using optional extra external storage): Connect the SATA to USB adapter to your Pi using an available USB port and connect your SSD or HDD to the adapter.

Step 3: Connect to the Pi over SSH

Step 4 (only if using external storage): Get storage UUID

In order to mount the external drive as a directory, we need to get the UUID of the device. Run the following command and take note of the UUID of your external drive. It will be in the form XXXX-XXXX.


Step 5: Get the code.

Run the following lines to grab all the packages you’ll need. You can omit ffmpeg if you plan on doing the video processing on another machine.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip git exfat-fuse ffmpeg
sudo apt-get remove python-setuptools
sudo apt-get install python-setuptools libjpeg8-dev

“Why are we removing and then installing the same thing” I hear you asking. Because something is wrong with python-setuptools right now and you have to, and because I said so.

sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib
pip2 install Pillow

This may take a while. Leave it alone

We installed Git earlier so you can use it to pull the code you will need. Use the following lines of code to pull down the repository to the /home/pi directory using git.

cd /home/pi
git clone

Now all the code you need for the system is pulled down in this directory. Don’t say I never did nothing for you.

Now we’re going to initialize the environment in order to prepare it for service

sudo python3 /home/pi/viadoxic-spypi/
source /home/pi/.bashrc
sudo poweroff

The SpyPi will power off. Continue on before rebooting.

Step 6 (only if using a project box): Shove It in the Project Box

Not hard. Just get everything in there. Here is a picture of one of my setups that utilizes the project box.

Step 7: Personalize the code if needed

This script is the one that actually does the recording when motion is detected. It records for 60 seconds by default before calling the motion detection script again. To change the amount of time it records for, open it in a text editor with

sudo nano /home/pi/viadoxic-spypi/

Change the value of the recTime variable to change the recording time. I.e. if you want to record for 45 seconds when motion is detected, change the line to be


Also, if you have not named the recordings directory “recordings” or if you’re using an external storage device, then you have to change it in here too.

Step 8: Test

Measure twice, cut once. This project has nothing to do with carpentry, but you get the picture. This system is meant to be quick to deploy and quick to start, so we will do some testing in a controlled environment to make sure all the parts are playing nice with each other before deploying the SpyPi in the wild.

Connect the camera module to the ribbon cable and connect the other end to the Pi (DO NOT DO THIS WHILE THE RASPBERRY PI IS RECEIVING POWER, EVER. Camera setup tutorial here if you need it). Boot the Pi and ssh in. We’re going to run scripts you got from Git in step 4 to make sure it’s working correctly.


This will start the motion detection. Now give it a few seconds to get baselines and then wave your hand in front of the camera. You should see the command line say that motion has been detected and is going to start recording. It will then record for an amount of time as defined in step 7 to the recordings directory that was created during the initialization process. When it’s done recording, you should see a message that it has completed recording and is launching motion detection again. Then the cycle repeats.

When you’re ready to stop the cycle, just press ctrl-c and type the following command


If everything worked correctly, you should be good to go.

Step 9: Deploy

Now that you’ve confirmed everything is working correctly, you can deploy your setup to wherever it’s going. This part is up to you. Put it wherever you want, however you want. Supply power to the Raspberry Pi either through my mobile power station or through the standard wall plug. Here are some very basic ideas I’ve come up with. You can see how the extended cables come in handy. If you want some more tips see my spycam tips page.

Hidden in some sheets in the closet

Hidden amongst some other electronics project stuff

Hidden in a backpack. From just about any distance it just looks like a tear in the bag or a place where a grommet used to be unless it’s in direct light like it is in this picture.

SSH in and start motion detection


Step 10: Convert Videos
When you’ve recorded all the videos you want, it’s time to convert them. The camera module records in .h264 format. We will convert it to .mp4 format. To convert the videos, run the script with this command

python3 /home/pi/viadoxic-spypi/

When this script finishes, the .mp4 files will be in the /home/pi/recordings/output directory. Copy them off the SpyPi and watch them as you see fit.

BIG NOTE: This script is really only supposed to be used in a pinch to render video on the Pi. The processing power on the Pi is super low so converting 1min videos takes forever. It is much more advised to transfer the files to a desktop or even a laptop first and then do the conversion. Shoot me an email if you have any problems with that.

Step 11: Support

If you have any problems, I’m almost always available through email at Just make sure to reference the project you’re working on so I’m not confused.


The script included in my project is a modified version of an amazing script written by skl on GitHub.