What You Will Need
If you’ve been following along with the previous projects, you should already have most of the parts. There are only a couple more required parts along with any other custom additions you’d like to add.
Auto-running The Python Script
With your wifi card plugged in and your Pi booted up to the desktop, right click on the wifi icon in the upper right hand corner of the screen (next to the clock). Select the wlan configuration option. From the configuration window, click on the dropdown menu and select “wlan”. Then set a static IP address in the “IP Address” field that isn’t being used by any other device on your network.
Then open up a command prompt. What we want to do is autostart our python script, and there are several different ways to do that. What worked well for me is to launch it after the Pi boots up to the destkop. So use the code below to edit the startup script and add a line that points to your python installation path and your python script.
sudo nano ~/.config/lxsession/LXDE-pi/autostart @/usr/bin/python /home/pi/simplecv.py
Disassembling The Camera Case
Once you’ve completed Step 1, you are now done with the software side of things. Now we can finally move on to taking stuff apart! To serve as the case for the security camera, I was able to find a dummy security camera online for cheap. It was extremely easy to disassemble, it was hollow on the inside, and it was just wide enough to fit the Raspberry Pi. The front of the camera had a nice array of LED’s, and a fake lens in the middle of them. I was able to remove the face lens and replace it with the Raspberry Pi camera, using hot glue to hold it in place.
Powering The Pi
Obviously, our raspberry Pi is going to need a power source. The general 5v microusb plug that you’ve been using to power your Pi should work just fine, but in case of a power outage (or if a perpetrator decides to unplug it), it’d be nice to have a backup. I decided to use a 4000maH emergency charger power bank. Since the Raspberry Pi 2 pulls about 950 mA, that gives us about 4 hours of power on a full charge. But unfortunately, the unit I purchased doesn’t quite fit in the security camera. However, I was able to take apart the casing and extract the LiPO battery and charging component. WARNING: If you decide to extract the battery, be very careful not to puncture or damage it.
Powering the Pi through the microusb port leads us to another problem, the added width of the microusb cable makes the Pi too wide to fit into the casing. An alternative is to power it through the GPIO ports using the pins highlighted in the diagram below. So I unsoldered the microUSB adapter and replaced it with these two wires, making sure not to confuse the ground and power wires. Plugging it in successfully power up the Pi, and we can run a 5v microUSB cable through the back of the casing to the battery.
Putting It All Together
It’s time to fit everything into the casing, hot glue it into place, wire it up, and put everything back together. You can tell it’s on whenever you see a red light on the camera. Now all you have to do is put it in an area you want monitored (not recommended for outdoor use, since it hasn’t been weatherproofed), then type in the Pi’s IP address and the webcam port number to pull up the stream. Then if motion is detected, you should get a notifcation email.