Using a Raspberry Pi, a Raspberry Pi camera module, a PIR motion sensor, a USB WiFi adapter, a handful of parts, and a couple of Python programs, you can construct a camera that will automatically snap photos or record short videos when something moves in front of the camera and will automatically upload the photos/videos to Dropbox. This instructable shows how to build a Raspberry Pi Motion Sensitive Camera.

My inspiration for making this was to help satisfy my curiosity about the behavior of my cats when I'm not home and to identify the local wildlife culprits that devour the plants in my garden. There are commercial products that can do this but I thought it would be fun to build one that works exactly the way I desire.

The Raspberry Pi executes a Python program that starts when the Raspberry Pi is booted and waits for motion to be detected by the PIR sensor. When motion is detected, the Raspberry Pi snaps a photo or records a short video and then uploads it to a DropBox account. The great thing about uploading to Dropbox is that the photos and videos are available to be viewed by the owner of the Dropbox account on any device (laptop, desktop, tablet, smart phone) from anywhere where internet access is available. When the upload is complete, the program sleeps for a few seconds and then waits again for motion to be detected.

There is a second constantly running Python program that monitors a switch on the side of the camera. This program illuminates an LED in the switch so you know when the camera is operational. When the program detects the switch being pressed, it blinks the LED in the switch and then halts the software in Raspberry Pi. The LED in the switch turns off to indicate that it is safe to unplug the power to the camera.

There is an additional LED mounted on one of the side panels that is illuminated when the Raspberry Pi is connected to power.

A more detailed explanation of how the software works is provided in step 20.

The diagram shows the wiring of the various components to the Raspberry Pi.

The case for the camera was made with 1/8" thick birch plywood cut using a Epilog Helix laser cutter.

This instructable assumes you have basic experience with setting up and running a Raspberry Pi, that you have experience soldering, and that you have access to and experience with a laser cutter.

I made this at TechShop.

Step 1: Parts

The following parts are needed to construct the Raspberry Pi Motion Sensitive Camera:

Raspberry Pi Parts:

  • 1 Raspberry Pi model B 512MB RAM (Available on Amazon or Adafruit ID 998) (photo 1)
  • 1 16GB SDHC class 4 card (photo 2)
  • 1 HK Mini USB WiFi 150Mbps wireless adapter 150M LAN 802.11n/g/b with antenna (available from Amazon) or other supported WiFi adapter for Raspberry Pi (photo 3)
  • 2 3/4" #4-40 Machine screws and nuts (photo 4)
  • 2 1/4" Round nylon spacers for #4 or #6 screws (photo 4)

PIR Sensor Parts:

  • 1 PIR Sensor revision B (Parallax Product ID 555-28027) (photo 5)
  • 2 M2 12mm Machine screws (photo 6)
  • 4 M2 Nuts (photo 6)
  • 2 M2 Washers (photo 6)
  • 3 20cm Female to female jumper wires (Amazon B00AYCON8Y) (photo 25)

Raspberry Pi Camera Parts:

  • 1 Raspberry Pi camera board (available on Amazon or Adafruit ID 1367) (photo 7)
  • 4 M2 10mm Machine screws (photo 8)
  • 4 M2 Washers (photo 8)
  • 4 M2 Nuts (photo 8)
  • 12 #4 Flat nylon washers (Amazon Supply part number B000FN1560) (photo 8)

Shutdown Switch Parts:

  • 1 16mm Illuminated push button red momentary switch (Adafruit ID 1439) (photo 9)
  • Heat shrink tubing (1/16" diameter) (photo 10)
  • 4 12" Jumper wires (one end male, one end female) (Sparkfun part number PRT-09385) (photo 11)
  • 1 470 Ohm 1/4 watt resistor (photo 12)

Power Indicator Parts:

  • 1 Panel mount red LED (Jameco Part no. 141111) (photo 13)
  • 2 12" Jumper wires (one end male, one end female) (Sparkfun part number PRT-09385) (photo 14)
  • Heat shrink tubing (1/16" diameter) (photo 10)
  • 1 470 Ohm 1/4 watt resistor (photo 12)

Case Parts:

  • 2 96mm White plastic wire pull handles (Liberty part number P604AEH-W-C available at Home Depot) (photo 15)
  • 4 #8 x 1/2" Sheet metal screws for use with the handles (do not use the screws that come with the handle - they are too long) (photo 16)
  • 24 #4-40 1/2" Machine screws and nuts for holding the case together (photo 17)
  • 1 Sheet of 24" x 18" 1/8" (3mm) birch plywood (not pictured)

Bottom Panel Parts:

  • 1 1/4-20 Round screw plate (Servocity part number 545468) (photo 18)
  • 4 #6-32 7/16" Pan head machine screws (Servocity part number 90272A147) (photo 19)
  • 4 #6-32 Nuts (Servocity part number 90480A007) (photo 19)

Panel USB Cables:

  • 1 Panel mount USB cable - type B female to micro-B male (Adafruit ID 937) (photo 20)
  • 1 Panel Mount USB Cable - type A male to type A female (Adafruit ID 908) (photo 21)

Power Supply:

  • 1 USB battery pack for Raspberry Pi - 4400mAh - 5V @ 1A (Adafruit ID 1565) (photo 22)
  • 1 USB power adapter 5 volts 2 amps (photo 23)
  • 1 6 foot USB cable with a type B male connector and type A male connector (also called USB printer cables) (photo 24)


  • Tripod (photo 26)

Tools (not pictured):

  • Soldering iron and solder
  • Heat source for heat shrink tubing (heat gun, matches, lighter, or candle)
  • Wire cutters
  • Wire strippers
  • Small Philips head screw driver
  • Hemostat
  • Needle nose pliers
  • Painter's tape(to help hold screws in place on the front panel)
  • 120 grade sandpaper

Equipment for installing Raspberry Pi software (not pictured):

  • HDMI capable computer monitor
  • USB keyboard
  • USB mouse
  • Ethernet cable
<p>Do you have an updated one for the Raspberry Pi 3 B? Since it has ethernet, wireless and some other features? I would like to know how to set it up without the PIR but with a laser 'trip wire' type of method so if anyone breaks the laser beam it records, IR and motion simply cause too many false positives. </p>
<p>Sorry for the delay in responding, with respect to the PI 3, it should work with the built in wireless without any changes to the instructions in this instructable. You could do this with a laser trip wire: you'd need a circuit that would act like a switch and then connect the two wires from that switch to GPIO 23 and GND like the PIR sensor and it should work. You might need to change line 155 of rpi-ms-camera.py from GPIO_RISING to GPIO.FALLING. I did some searching and there's a circuit at http://www.edaboard.com/thread205002.html that might work for you: you'd have to connect GPIO 23 and GND to the relay connections on the right side of circuit diagram. </p>
<p>I'm trying to use this without the box or shutoff light. I set up the RPi, downloaded the Python script &amp; the dropbox uploader. Whenever I start the script from the terminal it SEEMS like it should work -- it sends the IP address &amp; says waiting for motion, but the PIR never activates. I know the PIR works -- tested it with the &quot;Parent Detector&quot; exercise from rpi.org -- but I can't figure out why it won't work here. Any thoughts?</p>
<p>The only suggestion I have is to recheck the wiring between the Pi and your PIR sensor and make sure it's connect as described in step 15.</p>
<p>I have a problem with my internet connection going down. Where should I test for internet connection to keep the program from failing when the internet connection is lost? The program runs fine on first boot, but if the internet connection fails the program crashes. I would like to be able to test for a connection, then proceed to upload files.</p><p>Thanks,</p><p>not_a_programmer </p>
<p>There's an article on the Raspberry Pi site (https://www.raspberrypi.org/forums/viewtopic.php?f=30&amp;t=20149) that talks about how to make the Pi automatically reboot if the internet connection is lost. I haven't tried it myself, so I can't vouch for it but it might be worth looking into. </p>
<p>Hi, I got as far as the rip-ms-camera.py -firsttime but must have messed up. I didn't get the connection to Drobpox (it wouldn't let me create an app named rpi-ms-camera and now can't run the -firsttime script again - it gives me parameters, not what I saw the first time. I tried deleting and reinstalling, but there must be a configuration file somewhere. Can anyone tell me where that might be?</p><p>Thanks,</p><p>Bruce</p>
<p>What happens when you use --firsttime is that a program I reused from github that comes from (https://github.com/andreafabrizi/Dropbox-Uploader.git) runs and sets up dropbox on the Pi. I'm not familiar with all the details of how that works and how to undo what it does. My best recommendation, and I really hate to recommend this because it's a pain, would be to start from a new image Raspbian and do the install from the very beginning of step 9.</p>
<p>hi nice tutorial </p><p>is there way to usb camera.</p><p>thanks.</p>
<p>What a great project, but dude! What did you pay for that laser? Costs more than the Pi, no? </p><p>But the code works perfectly, thanks!</p>
<p>Glad to hear that you used the code with no problems! The project doesn't use a laser. The PIR sensor it uses detects motion by measuring changes in the infrared (heat) levels emitted by surrounding objects. The PIR sensor I used costs about $13.</p>
<p>mmm... yeah, I meant the '45 watt Epilog Helix Laser cutter'. Not really a garage sale item. Just jealous.</p>
<p>How download exactly works? I click at the Download pdf button but only appears invitation to go pro. And No Thanks is the other choise and nothing</p>
<p>You have to be a Pro member to download a PDF.</p>
<p>Thank you for the Instructable! Your documentation level is absolutely excellent :)</p><p>I am building a similar system to monitor a bird feeder on our backyard. At the moment I am looking for a weatherproof case for the whole system.</p>
<p>i love what you have going on here but a few modifications i wish i could make would be a solar panel and a lithium ion battery pack. seeing i would be using it for a trail camera where a ac power source is limited.</p>
<p>I made this project and it works very well. However, I 'd like to add an externally powered lighting device to turn on when the sensor is tripped, it this possible?</p>
<p>What is the res of pics and vids. I need to know the capacity of pics and vids. When it fills up will it overwrite oldest pics and vids?</p>
<p>Since I did not know how to tell what the capacity limit is for a user's DropBox account, the program does not try to manage space by deleting or rewriting files in DropBox. However, the program does delete the photo/video off the Raspberry Pi after it has been stored in DropBox.</p>
<p>The resolution of the photos is 1024x768. The photos are files of approximately 464KB in size. The video resolution is 640x480. 15 seconds of video creates a file approximately 6 MB.</p>
<p>You can use Kerberos.io, it's open-source and user friendly to install and configure. You can find more information on their website.</p>
<p>Excellent documentation on the python program, thank you. I think you've made it pretty clear for me to modify it. I have my Pi cameras connected to a NAS box via NFS - I want them to simply write stills or videos to /mnt/picam# and not upload to DropBox, not delete.</p>
<p>Great documentation, one minor improvement: the PIR sensor I used (HC-SR501) did not function with a supply voltage of 3.3V. I connected the red wire of the PIR sensor to pin 4 of the GPIO (+5 V), that worked!</p>
<p>I'm a complete beginner at programming; can someone tell me how to change the code so that the camera takes pictures instead of videos please?</p>
<p>To make the code take pictures instead of video you change one the options when you run the program. I explain how this works in &quot;Step 9: Prepare the Raspberry Pi Software&quot;. If you scroll down to the the part that says &quot;The sixth step is to...&quot;, you'll see an explanation on how to do it. </p>
<p>I've been working on a very very similar idea to this but the PIR sensor was way to sensitive to be outside. I reduced the onboard sensitivity as much as it would go and I still get a ton of false positives. Do you have any experience with this?</p>
<p>I have not tried mine outside. I've just used it inside where it is a more controlled environment: I did have a problem with the sensor picking up motion on the sides and I did come up with a fix for that - I described it on the last step of the instructable. There is some information here that might be helpful: </p><p>http://electronics.stackexchange.com/questions/30981/reducing-the-sensitivity-of-a-pir-sensor</p><p>Other than that I'm not sure what to suggest. </p>
great! documentation is just perfect. many thanks for sharing your project ☺
<p>This is a great idea, and very well documented. Thanks!</p>

About This Instructable




More by talk2bruce:Raspberry Pi Internet Monitor Laser Cut Raspberry Pi LCD Case Raspberry Pi Motion Sensitive Camera 
Add instructable to: