Pi Cam Part 1


Posted on March 20, 2017 at 8:00 PM

Raspberry Pi Security System Part 1: The camera.

A family member asked me to put a camera in our garage recently, and immediately I decided to use a Pi Zero. Back when I was interviewing for my current job, I was dabbling with the idea of making a wireless, battery powered IP camera that I was going to attach to my dog, and get some cool footage of my dog running around. I never fully finished that project because, at the time, giving the Pi Zero wifi involved either soldering on a wifi chip to the bottom of the Pi, or using the MicroUSB port. Also, at the time, battery powering a Pi Zero project was a bit outside my skillset.

Recently, with the help of Red Bear Labs, I was able to make a few of these IP cameras. I started the build back before the Pi Zero W came out, so this hardware guide is how to build one of these cameras on the Pi Zero 1.3. This project will be part 1 of a multi-part project, incorporating a few Pi zero's, a Pi 3, some software and some hardware. Ending, hopefully, with a fully functional security system that notifies the owner when there is movement.

Hardware you'll need:

  • A Raspberry Pi Zero 1.3
  • Red Bear IoT pHAT
  • Pimoroni Zero LiPo
  • 2x20 header pins
  • Raspberry Pi camera
  • Pi Zero Camera Cable
  • SD card
  • 1500maH battery
  • Basic Soldering equipment (Solder Iron, solder, solder wick)

Here's how to make it:

Start out by soldering the 2x20 pins onto the Pi Zero. These pins are necessary to attach any HAT's to the project. Start by soldering a pin on one corner, then one on the opposite side of the Pi. Doing it this way allows for the rest of the pins to be held securely in place as you solder them. I recommend always doing it this way when soldering anything, as it is easier to solder things that aren't moving.

After the pins are soldered onto the Pi Zero, the next step is attaching the Red Bear IoT pHAT (If you are using a Pi Zero W, this step can be skipped). Similar to earlier start by soldering one pin on one corner, then solder a pin on the far side. Having one on either side will keep everything still while you solder the rest of the pins into place.

At this point you have soldered the Pi to the wifi HAT properly. The next part that we need to solder on is the Pimoroni ZeroLiPo. This board gives us a small JST connector that will allow for this project to be powered by a battery. It gets soldered onto the end 8 pins on the pi. This board is small enough that it should remain stable after just one solder connection.

Here, we have all the tricky hardware parts done. The Pi has the wifi capabilities it needs, as well as the battery power it needs. Next we need to attach the camera. The thick end of the camera cable gets put into the camera ribbon slot. Metal contact side up towards the board. The thinner side of the cable gets put into the Pi, again with the metal connectors facing towards the Pi's circuit board.

I chose to use some double sided tape to mount the camera onto the body of the Pi System. The camera fits nicely next to the Zero LiPo. Go ahead and mount the camera like this if you wish, otherwise find an alternate solution.

The hardware side of this guide is done. Next we just need to get the Pi setup to stream it's video wirelessly. Start by loading up an SD card with standard rasbian Pixel. If unsure how to do this, reference my guide on it, here. Once the OS is loaded, put the SD card into the Pi, let the Pi bootup, and settle on the desktop. Connect the Pi to the wifi (top right corner). First thing to do will be change the hostname/password. Run the command:
sudo raspi-config
in a terminal window. From this menu, change your hostname to whatever you wish, change the password on the pi, and enable the camera. Once those settings are done, reboot the Pi.

Once the Pi comes back up, open up a terminal and type:
Under wlan0 you will see your Pi's IP addess. Make sure to note it down somewhere. The next few commands will install a package called Motion, and configure it to stream whatever the camera sees wirelessly. Run the following command to update your Pi:
sudo apt-get update
Depending on you internet connection, this command may take some time to do everything. Once the update command is done, run the following command:
sudo apt-get install motion After the install is over, we will configure Motion properly.

A few notes before we start, Motion will by default record motion detection. For some reason, this is crashing my Pi Zero, so for now we will disable motion detection. At a later date we will be setting up a Pi 3 to handle input from multiple of these IP cameras. At that point we will have the Pi 3 handle the motion detection. First thing we need to do to configure Motion is tell the daemon to always be on. Run the following command:
sudo nano /etc/default/motion
to open and edit a config file, change start_motion_daemon=no to start_motion_daemon=yes

The next command will bring up the configuration file for motion itself: sudo nano /etc/motion/motion.conf
In here you are going to need to find the following lines, and modify them to match mine:
        daemon on
        width 640
        height 480
        framerate 100
        stream_localhost off
        set motion threshold to 300000
        set stream fps to 30
These will set the stream resolution, the local framerate, allow for it to be viewed wirelessly, practically disable motion activation, and set the stream framerate.

After this, there is just one more section. Currently, the Pi will work properly, but the proper drivers are not loaded for the Pi Camera. Run the following command:
sudo nano /etc/init.d/motion
In this file, add the line sudo modprobe bcm2835-v4l2 after the line that says 'chown'. Reboot the pi, and if you open up a web browser on another computer to "ipaddresofpi:8081" you should see the camera streaming whatever it sees!

Parts links (as of March 2017):

Raspberry Pi Zero 1.3 Camera Version
IoT haT
Zero LiPo
Raspberry Pi Camera Module V2 - 8 Megapixel,1080p
Arducam 5 Megapixels 1080p Sensor OV5647 Mini Camera Video Module with 15 Pin 1.0mm Pitch to 22 Pin 0.5mm and 15pin to 15pin 1.0mm Ribbon Cable for Raspberry Pi Model A/B/B+, Pi 2, Pi 3 and Pi ZERO
SanDisk Ultra 32GB microSDHC UHS-I Card with Adapter, Grey/Red, Standard Packaging (SDSQUNC-032G-GN6MA)


Enter your Name and Email to receive notifications about new posts

Like what you see?

Consider backing us on Patreon to help cover server/project costs! Shop using our
Amazon Affiliate link! Follow us on Social Media!

Contact Me

Feel free to email me at mwagner@hackmypi.com with any questions!