Raspberry Pi Motion Sensitive Camera

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.Raspberry Pi Motion Sensitive Camera

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)

Miscellaneous

  • 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

Step 2: Cut the case parts using a laser cutter

The first step is to cut the parts for the case out of a sheet of 1/8″ (3mm) birch plywood. A 45 watt Epilog Helix laser cutter at TechShop was used to cut out and engrave the parts. All of the case parts can be cut out from one 24″ x 18″ sheet of the plywood.

The design is shown in the first diagram. The black lines will be cut by the laser cutter; the blue lines will be etched using a low power cut; green text will be engraved; red lines will not be cut – they are included to show the outline of the parts. I used the color mapping capability of the Laser cutter to specify the settings for cutting and engraving. The setting used are shown in the right hand side of the “Color Mapping” screen capture.

All of the finished parts together are shown in photos 1 and 2.

The individual parts are:

  • Front panel with closeups of the engraving (photos 3 – 10)
  • Back panel (photo 11)
  • Bottom panel (photo 12)
  • Left panel (photo 13)
  • Right panel (photo 14)
  • Top panel (photo 15)

Photos 16 and 17 show a closeup of the cutouts that will be used for the screws and nuts that hold the case together. How these are used are described in step 13.

The burn marks left by the laser can be removed with a gentle sanding using 120 grit sandpaper.

The laser cutting design files are in the ZIP file attached to this step. The file contains CorelDraw (.cdr) and Encapsulated PostScript (.eps) files for the design and the file for loading the color mapping data for the laser cutter. See page 113 of https://www.epiloglaser.com/downloads/pdf/mini_he… for details on how to use color mapping.

Step 3: Prepare the shutdown switch

Using the following parts: push button switch (photo 1), jumper wires (photo 2), 470 ohm resistor (photo 3), and heat shrink tubing (photo 4), prepare the switch:

  1. Cut four lengths of heat shrink tubing (photo 5).
  2. Cut off the male ends of the jumper wires (photo 6).
  3. Strip the ends off the wires (photo 7).
  4. Slide the heat shrink tubing onto the wires (photo 8).
  5. Using photo 9 as a guide to the terminals on the switch, solder the resistor to the positive (+) terminal (photo 10).
  6. Attach and solder the red wire to the resistor (photos 11 and 12). Cutoff the excess wire on the resistor.
  7. Attach and solder the black wire to the negative (-) terminal (photos 13 and 14) using photo 9 as a guide.
  8. Attach and solder the blue wires to the remaining terminals (photo 15).
  9. Slide the heat shrink tubing over the resistor and over the exposed wires soldered to the terminals (photo 16). Use a heat gun, lighter, candle, or match to shrink the tubing.

The completed switch is shown in photo 17.

Step 4: Prepare the LED power indicator

Start the assembly of the LED power indicator with the panel mount LED (photo 1) and one 470 ohm resistor (photo 2).

  1. Using wire cutters, shorten the length of the resistor lead (photo 3).
  2. Clamp the resistor to the longer LED wire using a hemostat (photo 4 and 5).
  3. Solder the wires together and remove the hemostat (photo 6)
  4. Cut two lengths of heat shrink tubing (photo 7)
  5. Cut the male ends off of two jumper wires (photo 8)
  6. Slide the heat shrink tubing on the jumper wires and strip the ends (photo 9)
  7. Attach and solder the red jumper wire to the resistor (photos 10 and 11). Cutoff the excess wire on the resistor (photo 12).
  8. Attach and solder the black jumper wire to the other wire on the LED (photos 13 and 14).
  9. Slide the heat shrinking tubing over the exposed wires (photo 15). Use a heat gun, lighter, match, or candle to shrink the tubing.

The completed LED power indicator is shown in photo 16.

Step 5: Assemble the left panel

Assemble the left panel as follows:

  1. Screw one of the handles (photo 2) to the left panel (photo 1) using two #8 x 1/2″ sheet metal screws (photo 3) as shown in photos 4 and 5.
  2. Attach the type B female to micro-B male panel USB cable (photo 6) to the panel as shown in photos 7 and 8.
  3. Attach the shutdown switch (photo 9) to the panel as shown in photos 10 and 11.
  4. Attach the LED power indicator (photo 12) to the panel as shown in photos 13 and 14.

The left panel is now complete.

Step 6: Assemble the right panel

Assemble the right panel as follows:

  1. Screw one of the handles (photo 2) to the right panel (photo 1) using two #8 x 1/2″ sheet metal screws (photo 3) as shown in photos 4 and 5.
  2. Attach the type A male to type A female panel USB cable (photo 6) to the panel as shown in photos 7 and 8.

The right panel is now complete.

Step 7: Assemble the bottom panel

Assemble the bottom panel as follows:

  • Screw the round screw plate (photo 2) to the bottom panel (photo 1) using four #6-32 7/16″ pan head machine screws and nuts (photo 3) as shown in photos 4 to 6. Tighten the screws firmly.

The completed bottom panel is shown in photo 7.

Step 8: Create the Dropbox Platform app

In this step, you will create a Dropbox platform app. Creating the app will allow the Raspberry Pi Motion Sensitive Camera to be able to upload photos and videos to your Dropbox account.

Create a Dropbox account if you don’t have one already. Go to http://www.dropbox.com and click on the “Sign up” button. If you already have a Dropbox account, sign in to Dropbox.

  1. After you have signed in, go to http://www.dropbox.com/developers. Click on “App Console” as shown in screen capture 1. The “Your apps” page will display.
  2. Click the “Create app” button (screen capture 2).
  3. Select the “Dropbox API app” option (screen capture 3).
  4. Select the “Files and datastores” option (screen capture 4).
  5. Select the “Yes – My app only needs access to the files it creates” option (screen capture 5).
  6. Use “RPi-MS-Camera” as the name for application and enter it into the text box (screen capture 6).
  7. Click on the “Create app” button (screen capture 7).
  8. You have now authorized your application to access Dropbox. Print the screen. You will need to enter the App key and the App secret (screen 8) on your Raspberry Pi in the next step.

Step 9: Prepare the Raspberry Pi software

The first step in preparing the Raspberry Pi is to install and configure the Raspbian software:

  1. Connect the Raspberry Pi camera to the Raspberry Pi using the instructions that come with the camera module.
  2. Download and load Raspbian (http://www.rasbian.com/RaspbianImages) onto a SD card. Instructions for how to do this can be found here (https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/overview). I used the September 2014 version of Raspbian: I would recommend using this version or a later one for this project: don’t use an earlier version.
  3. Insert the SD card into the slot on the Raspberry Pi.
  4. Connect the Raspberry Pi to a display, keyboard, mouse, LAN with access to the internet, and a 5 volt USB power adapter as shown in the “Raspberry Pi Setup” diagram.
  5. Boot the Raspberry Pi and perform the first time configuration according to the instructions here (https://learn.adafruit.com/adafruits-raspberry-pi-lesson-2-first-time-configuration). When configuring the Raspbian, do not configure the graphical user interface to start automatically. Make sure to enable the camera and it’s a good idea to change the password for the Raspberry Pi at this time.

The second step is to download the Python programs that control the shutdown switch and that snap pictures or take photos when motion is detected. Create the directory where the Python programs will reside and where the photos and videos will be stored using these commands:

cd /home/pi
mkdir python_programs
cd python_programs
mkdir camera_output

Issue the following two commands to get the Python programs:

wget "https://s3-us-west-1.amazonaws.com/talk2bruce/instructables/rpi-ms-camera/rpi-halt-btn.py"
wget "https://s3-us-west-1.amazonaws.com/talk2bruce/instructables/rpi-ms-camera/rpi-ms-camera.py"

The third step is to install the Dropbox uploader and configure it use the App key and the App secret from step 8 “Create the Dropbox Platform App”. Install the uploader with the following commands:

cd /home/pi
git clone "https://github.com/andreafabrizi/Dropbox-Uploader.git"

if this command fails, you will need to install git with the command below and then re-issue the git clone command above:

sudo apt-get install git-core

After installing the Dropbox-Uploader from git, change to the Python programs directory with the following command:

cd /home/pi/python_programs

Issue the command below to configure the Dropbox uploader:

sudo python rpi-ms-camera.py -firsttime

You should ignore the five things that are listed on the screen as things to do – you did those in the Step 8 of this instructable. What you do need to do is to enter the app key and app secret from step 8 and select “a” for the permission type (see the first arrow on Screenshot 1). After you hit enter on the permission type, you will be instructed to enter a web address into a browser (see second arrow on Screenshot 1). Carefully write down the web address and go to a computer with a web browser and enter it. After you enter it, the web browser will display a page asking you to allow the app to access it’s folder on Dropbox (screenshot 2). Click the “allow” button. The next web page displayed will let you know that the app was successfully connected to Dropbox (screenshot 3). Hit “Enter” as instructed on the Raspberry Pi screen. You will get confirmation that the setup completed on the Raspberry Pi as shown in screenshot 4. If it fails, it’s most likely due to mistyping of the app key, app secret, or the web address. Try again by typing in the command above and re-entering the information.

Next, test the connection to Dropbox by issuing the command:

sudo python rpi-ms-camera.py -test

This command will send a file containing the IP address of your Raspberry Pi to Dropbox. The output of the command is shown in screenshot 5. You should find the file in the application in the App folder in your Dropbox account.

The fourth step is to configure the Raspberry Pi for use with your wireless network. Edit the file “wpa_supplicant.conf” with the command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add the following lines to the bottom of the file substituting the name of your wifi network and your wifi password as shown and save the file. If you are unfamiliar with how to use the nano editor, howtogeek has a nice Beginner’s Guide to Nano.

network={
  ssid="my wifi network name"
  psk="my wifi password"
}

The file should look like the what is shown in screenshot 6. More details on how to configure the Raspberry Pi for different kinds of wifi networks can be found on the Sparkfun website.

The fifth step is to configure the system to start the Python program that monitors and illuminates the shutdown button during the system boot process. Edit the file “rc.local” with the command:

sudo nano /etc/rc.local

Add the line command below to the bottom of the file before the line that says “exit 0” and save the file.

python /home/pi/python_programs/rpi-halt-btn.py&

The file should look like the one in screenshot 7.

The sixth step is to configure the system to run the Python camera program when the WiFi on the Raspberry Pi is up and running. When the Python camera program is running, it waits for motion to be detected and then takes photos or short videos and uploads them to Dropbox. The command to start the program is placed in the “etc/network/interfaces” file. Edit the file with the command:

sudo nano /etc/network/interfaces

If you want to have the camera take photos, add the following command to the bottom of the file:

post-up python /home/pi/python_programs/rpi-ms-camera.py -p

If you want to have the camera record videos, add the following command to the bottom of the file:

post-up python /home/pi/python_programs/rpi-ms-camera.py -v

Screenshot 8 shows what the file should look like when configured to take photos.

Configuration of the Raspberry is now complete.

The last step is to shutdown the Raspberry Pi with the command:

sudo halt

After the Raspberry Pi shuts down, disconnect all the cables but leave the SD Card in the socket on the Raspberry Pi.Raspberry Pi Motion Sensitive Camera schematic

Step 10: Mount the PIR sensor on the front panel

Using the two M2 machine screws, two M2 washers and four M2 nuts (photo 2) mount the PIR sensor (photo 3) to the front panel (photo 1) as follows:

  1. Place the two washers over the holes on outside (non-engraved) of the panel and insert the the machine screws (photo 4).
  2. While holding the screws in place (painter’s tape can help hold the screws in position), flip over the panel and screw on two of the nuts (photo 5).
  3. Slide the PIR sensor onto the screws and secure it in place using two nuts (photo 6). Make sure the connector pins are facing down over the “PIR Sensor” engraving.

The mounted PIR sensor is shown in photo 7.

Step 11: Mount the Raspberry Pi on the front panel

Using two 3/4″ #4-40 Machine screws, nuts, and nylon spacers (photo 1), mount the Raspberry Pi on the front panel as follows:

  1. Insert the screws into the outside (non-engraved) side the panel (photo 2).
  2. While holding the screws in place (painter’s tape can help hold the screws in position), flip over the panel (photo 3).
  3. Slide the nylon spacers on to the screws (photo 4).
  4. Gently slide the Raspberry Pi on to the screws (photo 5).
  5. Secure the Raspberry Pi using the nuts (photo 6). Do not over tighten the nuts: they should be “monkey tight”, not “gorilla tight”.

Step 12: Mount the camera on the front panel

Using four M2 10mm machine screws, four M2 washers, twelve #4 flat nylon washers, and four M2 nuts (photo 2) mount the Raspberry Pi camera (photo 1) as follows:

  1. Place a washer over each of the holes on the outside of the panel (non-engraved side) and insert the four screws (photo 3).
  2. While holding the screws in place (painter’s tape can be used to hold the screws in position), flip over the panel and slide two nylon spacers over each of the screws (photo 4).
  3. Place the camera over the screws, put a nylon spacer over the screw and gently screw the nut in place (photos 5 and 6). Do not over tighten the nuts. The mounted camera is shown in photos 7.

The completed front panel with the PIR sensor, camera, and Raspberry Pi is shown in photos 8 and 9.

 

For more detail: Raspberry Pi Motion Sensitive Camera

Scroll to Top
Read previous post:
Turning your Raspberry Pi into a personal web server

LAMP is an acronym that stands for LinuxApacheMySQLPHP and are components required to run a Dynamic HTML webpage. This instructable...

Close