Motion activated Camera

Introduction

In this post I'll discuss using a Raspberry Pi to build a motion sensing camera.  I wanted a device that had a built in motion sensor and could take pictures and other actions when it detected motion.  Originally, I also wanted this device to be something I could move around and in places that were not close to a plugin, so it needed to run on batteries.  The device I ended up building can only run for about 6 hours on batteries, which is not a full day.

The underlying software is written in Python and can be customized to respond to motion as well as take pictures at various intervals.  Here's what it looks like when finished:


Parts

Here's what you need to build one:
The software and STL files for the case can be found on gitlab (https://github.com/man-vs-electron/mobicam).  

The Infrared PIR sensors are quite cheap.  In fact, you can't purchase one.  You have to purchase them in packs of five.  I've found them to be reliable and easy to use.  The only problem, as mentioned elsewhere in this blog, is that they can't "see" through windows.  

The night vision camera has the normal IR filter removed.  This results in pictures that have washed out color, but it can see better at night.  The camera linked to above is a drop-in replacement for the normal Pi Camera and includes two infrared LEDs.  Their range is limited, so if you are planning on taking a picture of a whole room, you might want to add an additional infrared light.

The Raspberry Pi included in the list is an older model.  The reason for the specific model is that the insert for the case has holes and small posts that align with the holes in the Pi.  If you want to use a different Pi, you'll need to deal with how it gets attached to the insert.

Adafruit warns about making sure that the battery and the PowerBoost 1000C match up properly.  Make sure to head their advice.  But once you've 

Acquiring a Case

The STL files for the case can be found in the gitlab repository listed above.  There are three files, one each for the top, bottom, and the insert.  I'm still learning Fusion 360 and the case leaves a lot to be desired, but it's a start. 

Note that there's no button hole for the button in the back.  I drilled a hole in the back with a Dremel.  Also, the hole for the PowerBoost plugin is too small.  You'll need to Dremel that hole as well so it's a bit bigger.  Finally, the inset is specifically for the Raspberry Pi Model B.  The holes will line up so you can bolt the Pi down to the inset.  Other Pi models will require different holes in the bottom.

Here's what it looks like with everything connected but the case still not closed.  I used Velcro to attach the battery to the bottom of the case.   



Here's the wiring diagram.  There are three LEDs.  The "Photo" LED is what will flash when a photo is taken.  The "Standby" LED will be on when the device is in standby mode.  The "Armed" LED will light when the system is actively watching.

The battery itself isn't shown in the wiring diagram.  It plugs directly into the PowerBoost chip.  The chip will charge the battery and then automatically switch to it if the main power gets cut off.  The power switch between en and ground can be used to turn it off.


The Software

The software is written in two files.  One file, mobicam.py, starts a python based http server so that the device can be armed and disarmed using http posts to the device on your local area network.  It also reports when motion starts and when it stops.  Finally, there is a 30 minute timer.

You can define what happens every 30 minutes by defining a new python file that defines the functions that the main fill will call.  If you don't specify any python module on the command line, the "default_callbacks" file will be used.  Otherwise, write a python file with your own callback functions and name it as a module on the command line when you start python.

Comments