Pizero Motion Detect Webcam Security System



Introduction: Pizero Motion Detect Webcam Security System

This system uses a pizero, wifi dongle and an old webcam in a customized matchbox case. It records motion detect videos at 27fps of any significant movement on my driveway. It then uploads the clips to a dropbox account. Also can view the logs and change the configuration via dropbox.

Step 1: Setting Up the Prerequisites

First update the operating system to the latest version as described here.

Then set up the wifi as described here.

Then you will need to set up OpenCv. There are good instructions on how to do this on pyimagesearch. If you are going for version 3.0 expect it to take a long time. One of the steps takes 9 hours to make. You will also need the python bindings which are explained on that page.

When you have got this all up and running you are ready to download the motion detect software.

Step 2: Setting Up the Motion Detect Software

The code can be found on bitbucket. Copy these files by using

git clone https://bitbucket.org/dani_thomas/multimotiondetect.git

or if you prefer download them individually.

The main part of this system is multiMotionDetect.py. It uses a lot of the multiprocessing queues and events.

First of all you need to decide where you want the video images stored MotionVideos and set this value in the globalConfig.json file. Then copy the config.json.txt and maskedAreas.json.txt to the root of this folder. The config.json.txt has the following setting which can be edited remotely.

"frameThreshold": "4",


"min_area":"650", "postSeconds":"7",






FrameThreshold: is the number of significant frames before motion is detected.

staticThreshold: is the number of static frames before we turn filming off.

minArea: is the minimum size of the area in order to be counted as significant.

postSeconds: This is the number of seconds from the end of filming for the movement to go through the queue. readCamNice: This is how much priority to be given to the

readCam process. This is between -20 and +20 (the lower the figure the higher the priority). But don't overdo it or you will crash the operating system.

checkMotionNice: The priority for the motion detect process.

writeCamNice: The priority of the camera writing process.

maxqsize: This is the number of seconds which is then multiplied by the frames per second.

I mostly only change the min_area to account for wind conditions.

If you would rather use a simple logger rather than the socket logger (below) change the import miaLogging to

import logging


and remove the log receiver from the motionDetect file and everything else should work fine.

If you want to run the motion detect automatically on startup.

First edit the script and check that the homedir points to where you have multiMotionDetect.py, then copy the motionDetect file to /etc/init.d ie

cp motionDetect /etc/init.d/motionDetect

Should be executable already but

chmod +x /etc/init.d/motionDetect

Finally register the script with

sudo update-rc.d motionDetect defaults

You can also start, stop and restart the system with

sudo /etc/init.d/motionDetect start|stop|restart

By default the miaLogReceiver socket logging will start at the same time. The other three programs are independent but use the same socket logger (but could easily be converted). I call all these using a cron script of different intervals. For instructions look here.

CheckRunning.py checks that multiMotionDetect.py is running and does a restart if not.

fileMaint.py does housekeeping on the video folders removing these after the given number of days. It removes subdirectories of the motion video folder set in the first paragraph. It checks that they start with "MV" so make sure you haven't got another directory of importance starting with the same characters within that folder.

Step 3: Accessing the Videos and Configuration Through Dropbox

Finally if you want to view your videos, logs and config files remotely then you will need to set up dropbox.

First get a dropbox account which is free. Then set up the API for python -https://www.dropbox.com/developers/documentation/... This includes downloading the sdk and registering the app to access the API.

When you've got a key enter that in the globalConfig.json file. More info on the system can be found on my blog dani cymru - cyber renegade If you find anything of interest or any questions please put a comment on the blog.



  • Epilog Challenge 9

    Epilog Challenge 9
  • Gluten Free Challenge

    Gluten Free Challenge
  • Sew Warm Contest 2018

    Sew Warm Contest 2018

We have a be nice policy.
Please be positive and constructive.