Spy your pet with a Raspberry Pi Camera Server

Michel Parreno
HackerNoon.com
5 min readAug 23, 2017

--

nom nom nom nom nom

This tutorial is the first part of my “ Spy your pet with a Raspberry Pi”. I own a little bunny called ‘Mochi’ and am often worried about him when I am not home. So, I decided to build an interactive cage to connect with Mochi whenever I am at work or traveling.

Building an interactive cage involves 3 main challenges :

  • Install a spying connected camera,
  • Build an automated food dispenser,
  • Access your camera and food dispenser from anywhere around the world

My first challenge was the spying camera system, which I’m going to describe in this tutorial.

Required equipment

Install the camera on your PI

Raspberry Pi 3

Firstly, turn off your raspberry Pi, and be cautious to avoid any static electricity on your hands. Plug the camera blue ribbon in the Raspberry PI as shown in the above image. To plug the camera, you have to slowly unclip the white plastic part, plug the ribbon, and clip the white part again.

Now, plug the ethernet cable, the keyboard, mouse and screen to your PI. Don’t forget to plug the SD Card containing Raspbian OS ! Finally, turn it on by pluging the power supply to it. After a few seconds you should see :

Raspbian Operating System on your Raspberry Pi

Enabling camera configuration on your PI

In order to use compatible libraries or softwares with your Pi Camera, you first need to enable its configuration on your Raspberry Pi options. Run the following command on your Pi Terminal (screen icon in the navigation bar):

Choose "camera" and select "Enable support for Raspberry Pi camera". Reboot when prompted and you’re done ! Several features should now be available for the camera:

  • raspistill that captures images (available directly with Raspbian)
  • raspivid to captures videos,
  • Motion which is what we are going to use

Installing Motion

Motion is a camera signal monitoring software that also have interesting motion detection features.

First, let’s be sure that everything on your Pi is up-to-date. Run the following in the Pi Terminal:

Now, let’s install Motion software on our Pi and activate the official driver for the camera.

To complete the process, we also have to tell the Pi to activate the driver after any reboot so our camera will always be available.

Because we want our camera server to run constantly, let’s set it as a daemon (background process) and start it automatically.

We are done with Motion installation ! Let’s configure it so we can have a camera server !

Configuring Motion

Create a backup and open the Motion configuration file

Find the options below and edit them as follows

Be aware that choosing a high resolution requires a larger bandwidth and your stream will lag if you have a low internet connection. You also have to pick a compatible resolution for the Pi (The stream won’t start if you don’t). Please check the Raspberry Pi available video modes.

OPTIONAL : save motion detection pictures

Testing our camera server from a local computer

First, let’s start our Motion server !

By now, you should be able to view the camera stream directly on your Pi. Search for the default web browser in the home menu of Raspbian and check the URL http://localhost:8081. You should see your camera server! But now, we want to be able to spy our pet from any device connected to our Wifi and also from anywhere outside home !

Plug the Wifi dongle to your raspberry Pi and configure the Wifi connection on it.

The official Raspberry PI Wifi Dongle

Run the following command in your Pi Terminal

On the following file, put your own SSID and Wifi Password.

Restart the nerwork interfaces

Now let’s get the local IP adress of your Pi by launching:

In the command line response, find the “inet addr” which will give you the Raspberry Pi IP

We are ready to test our camera server in all the devices connected to our home Wifi ! Take your phone or your laptop and go to → http://<replace this by your inet addr>:8081. You should see the camera stream !

Conclusion and next steps

Yay ! Now we have our local spy camera stream ! Say Hello to Mochi !

Our little friend is now under surveillance

However, we want to be able to view it from anywhere ! For this, I recommend using a dynamic DNS service. For a detailed explanation, you can check my next tutorial How to access your Raspberry Pi from anywhere.

What about building a food dispenser for your pet ? Get it all done with Build a connected food dispenser with Raspberry Pi.

--

--