In this project, I’ll be showing you how to assemble and configure a Raspberry Pi Zero W to be used as a WiFi security camera, which is also accessible over the internet.

We’ll be using an operating system called MotionEyeOS on the Raspberry Pi, which is a web-based, mobile and tablet friendly surveillance system. It can be used with both the Raspberry Pi camera or any USB web camera plugged into the Raspberry Pi. You can also set up motion detection with email notifications, take still images and time-lapse movies, and even configure it to upload media files to network storage locations or to cloud storage services.

Here’s a video of the build and the camera in operation, read on for the full step by step instructions.

What You Need To Build Your Camera

Optional Alternative (You’ll still need to buy the camera):

  • Pi Zero W Kit (Includes Pi Zero W, Case, SD Card, Power Supply & Camera Ribbon Cable) – Buy Here
What You Need To Build Your Pi Zero WiFi Security Camera

Assembling The Raspberry Pi Zero WiFi Security Camera

I’ve used a Raspberry Pi Zero W for this project because they’re relatively cheap and compact, making them perfect to mount discretely around your home. You can set up a couple of cameras around your home for less than $100. The W version has built-in WiFi, so there’s no need for an external WiFi or Ethernet adaptor to connect it to your home network.

Raspberry Pi Zero W

Let’s start by assembling the components into the Raspberry Pi Zero case.

If your Pi Zero came with a heat-sink, attach it to the board using the adhesive tape on the heat-sink.

Stick The Heatsink To Your Raspberry Pi Zero W

Once you’ve done that, you’ll need to connect the camera to the Pi.

The ribbon cable just slides into the connector with the contacts facing towards the board.

Clip The Ribbon Cable Into The Camera

Make sure that the black clip is pulled away from the connector to open it. Then push the black clip back into place to grip the ribbon cable once it is seated correctly in the connector.

Secure The Ribbon Cable Connector

Now do the same on the connector on the Raspberry Pi to connect the camera module to the Pi.

Plug The Camera Into The Raspberry Pi

Next open up the case and push the Pi into the back of the case. There are small pegs on the case which align with the screw holes on the Pi and the ports should all be aligned with the cutouts on the side of the case.

Install The Pi Into The Case

Next, clip the camera into place on the top cover and then close up the case to check that it all fits correctly.

Close Up Of The Case

We can now move on to preparing the SD card with the MotionEyeOS operating system.

Loading The Operating System Onto The SD Card

Use a card reader to plug the card into your computer.

Now you’ll need to download the MotionEyeOS software.

If you’re not using a Raspberry Pi Zero, or you’d like to use a different board, have a look at the list of Supported Devices to see which version of the operating system you should download.

MotionEyeOS Supported Devices

Go to the list of latest releases and make sure that you download the latest version of the software which is compatible with your board.

We’ll be using the Raspberry Pi version which was released on the 6th of June.

Latest Release For MotionEyeOS

Once you’ve downloaded the software, you’ll need to unzip it to a folder on your computer. I used Easy 7-Zip for this. Don’t try to flash the zipped image to your SD card, it won’t work.

You’ll then need to use an image flasher to flash the disk image to your SD card. The one recommended in the installation instructions on GitHub is Balena Etcher. Once you’ve downloaded and installed the software, you can flash the disk image.

You’ll need to first select the source file, which is the disk image that you unzipped in the previous step.

Download & Use Balena Etcher

Then select your destination target, which is your SD card.

Then click on Flash and wait for the software to write the disk image to your SD card.

Flashing The Image To The SD Card

Finally, you’ll need to tell your Raspberry Pi how to connect to your WiFi network.

To do this, use the template below. It’s a basic text file in which you’ll need to add your country code and then your Network name or ID and the network password.

You can find a list of country codes on Wikipedia.

Rename the file to wpa_supplicant.conf, making sure to change the extension as well and then put it into the 30MB settings partition which you’re able to write to on your SD card.

Once you’ve done this, your SD card is ready to be installed into your Pi for the first boot up.

Booting & Configuring Your Pi Zero Security Camera

You don’t need to attach a monitor for this next step, but it is helpful to check that you don’t get any error messages and to make sure that the Pi has finished booting up.

Boot Up Pi For The First Time

The first boot up takes about a minute or two to complete, it’ll boot up much faster than this after the first boot.

Boot Up Log

If you haven’t used a monitor then you’ll need to find the IP address of the Pi using a network analysing tool on your computer.

Once you’ve found the address, type it into your browser to access the Pi and it’s video feed.

MotionEyeOS Running

If everything is working correctly, the video feed from your camera should show up after a few seconds.

Test Camera Loading

If you open up the settings menu, you can also shutdown or restart your Pi, which you’ll need to do if you’re going to be disconnecting it to install elsewhere. If you’re asked for login details, the default username is admin, with no password.

Mounting Your Camera

I 3D printed a small GoPro adaptor to stick onto the back of the Pi case so that it can be mounted onto any standard GoPro mounts.

GoPro Mount For Back Of Pi Camera
GoPro Mount On Back Of Raspberry Pi Zero

I’m going to be using a suction cup mount to mount the Pi onto an outside window. It’s under cover, so it’s protected from direct sunlight and rain.

This mount also enables the camera to be positioned so that it’s pointing in the right direction.

Mount Raspberry Pi Zero WiFi Camera Onto Window Outside

You’ll need to power it using a USB power supply. You can also use a power bank to temporarily power it for a mobile surveillance system.

Raspberry Pi Zero WiFi Security Camera

Let’s have a look at the video feed outside.

MotionEyeOS Video Feed Outside
MotionEyeOs Camera Feed

You can also access the camera using your mobile phone or tablet by typing the same IP address into your device’s browser.

Configuring Port Forwarding To Access Your Camera Over The Internet

The last step is to configure port forwarding on your router, so that you can access the camera from the internet.

You’ll need to start by assigning a fixed IP address to your camera, so that it doesn’t change every time it re-connects to the network. This can be done in the MotionEyeOS settings menu. Set the IP configuration to manual and then change the IP address to the address you want to always assign to the camera. This should be out of the range that your router typically assigns addresses to otherwise you’ll land up with a conflict it that address has already been used.

For example, if your router typically assigns IP addresses in the 192.168.10.1 to 192.168.10.20 range then you should pick an address higher than 20, so something like 192.168.10.21 and onward for your cameras.

You might also need to change your Default Gateway to your Router’s address.

Next, you’ll need to set up port forwarding on your router. This is something I can’t really show you how to do because it’s very different for each router make and model. But you essentially need to login to your routers configuration page and then add a port forwarding instruction so that requests from outside your local network on a specific port are forwarded to a particular device, in this case, your Raspberry Pi camera.

Setting Up Port Forwarding On NetComm Router

Here’s the general idea of what you need to do:

  • You’ve got your Raspberry Pi’s local IP address (this is what you’ve been using to access the camera through your browser), you now need to know what port number it is communicating on. This is usually Port 80 by default. Since this is the default, it’s a good idea to change it to a port number that is unused by any other services as a security measure.
  • Next, you’ll need to find your router’s external IP address. This can be done by googling – “What’s My IP” from any device connected to the same internet-connected network.
    • This is the IP address you’ll need to type in over the internet in order to access your camera while you’re away from home. It is the IP address which your provider has assigned to your router. So this might change if you don’t have a fixed IP address arrangement with them.
  • Lastly, you need to choose an external port to forward. Again, you can choose any unused port. You’ll use the combination of your router’s IP address and this port number in your mobile device’s browser in order to access the camera.

Now that you have an external IP address and port as well as your internal IP address and port, you should have all of the information that you need to configure the port forwarding instruction on your router. This is the part that is very different for each router manufacturer and model, so you’ll need to figure out how to do this on your own router.

Essentially what you’re doing is telling the router that when an external request is sent to it on the particular port you’ve chosen, the router should forward the “web page” which is served to it when it calls the local IP address and port number so that you’re able to see it from outside the network.

Once this is done, you should be able to access your camera over the internet in the same way you could do it locally. If you’re still unsure how to do this, try searching for setting up Port Forwarding on your specific router make and model.

Let me know if you’ve built your own Raspberry Pi Zero WiFi Security Camera in the comments section. What are you using it for?

Share This Guide

Raspberry Pi Zero WiFi Security Camera Social

2 Replies to “How To Make A Raspberry Pi Zero WiFi Security Camera”

  1. Good afternoon,
    I love your guide. The one change I would do is in the section about port forwarding. While I agree with you that you can’t possibly show how to do this with every router out there, you could specify which port to forward to help people who are not totally familiar with the process of part forwarding.

    Other than that, the guide is great.

    1. Hi Pierre,
      Thanks for the feedback and advice. I’ve added a bit more information and general instructions for port forwarding and which ports to use, hopefully this helps others out!

Leave a Reply

Your email address will not be published.