This surveillance system detects motion of any object within its camera’s range, captures the image and stores it in Raspberry Pi. You can retrieve images from Raspberry Pi any time. Since Raspberry Pi camera is static-sensitive, take good grounding measures before you touch it. Connect the camera as shown in Fig. 1.

Fig. 1: Raspberry Pi and the camera
Fig. 1: Raspberry Pi and the camera

Installation of camera
Open Raspi config utility using the command:

 

$ sudo raspi-config
Explore Circuits and Projects Explore Videos and Tutorials

Now, enable the camera as shown in Fig. 2.

Fig. 2: Enabling the camera
Fig. 2: Enabling the camera

If your firmware is old, you need to update and upgrade it using the command mentioned below to see the camera enable option:

 

$ sudo apt-get update
$ sudo apt-get upgrade

After enabling and connecting the camera to Raspberry Pi, use following commands to check if it is working well. The first command is raspistill, which is used to take still pictures. For example, if you want to capture an image, type the following command (also see Fig. 3):

Fig. 3: Capturing an image
Fig. 3: Capturing an image

 

$ raspistill -v -o image.jpg

If red LED of the Raspberry Pi camera glows for some time, it shows that the image has been recorded. You may check the image under Home folder in Raspberry Pi to ensure that the camera is properly installed.

Capturing motion
We have two methods for motion detection. First method uses the light-weight motion detection Python script while the second method uses ‘motion’ software to detect motion and capture images.

Method 1: Using Python script. Python script depends on Python Imaging Library, which is meant for analysing and manipulating images. So we have to install the library using the following command (also see Fig. 4):

READ
LOW-POWER VOLTAGE DOUBLER
Fig. 4: Installing Python script
Fig. 4: Installing Python script

$ sudo apt-get install python-
imaging-tk

We can get the script from the link mentioned below:

https://github.com/skl/raspberry-pi-cam/archive/master.zip

Make the script executable by using the command (also see Fig. 5):

Fig. 5: Making the script executable
Fig. 5: Making the script executable

 

$ chmod +x picam.py

The script is designed to store images in a directory named picam under Home directory, so create it as shown below before executing the script:

 

$ mkdir ~/picam

We shall be ready to run the script after giving the following command:

 

$ ./picam.py

The script will turn on red LED of the Raspberry Pi camera and start taking low-resolution images. It will then compare them and look for movement by comparing the pixels in the images. If it detects any changes in the pixels, the script will capture a higher-resolution image.

The script is written in such a way that it stores only high-resolution images. All these images are saved in the ~/picam folder which we had created. Note that, if the camera is placed in a windy area then set the threshold variable in config file to a higher value than the default.

For running the script during booting, we need an init script that runs the picam.py script and kills it before shutting down the Raspberry Pi. To get the script, issue the command given below:

 

$ wget http://pastebin.com/AfqbjQrb
-O picam_init

Move the script into its correct location using the command (also see Fig. 6):

Fig. 6: Moving the script to desired location
Fig. 6: Moving the script to desired location

$ sudo mv ~/picam_init /etc/init.d/
picam

Next make the script executable using the command (also see Fig. 7):

Fig. 7: Making the script executable
Fig. 7: Making the script executable

$ sudo chmod +x /etc/init.d/picam

To make the script start during booting, type the command given below (also see Fig. 8):

READ
ULTRASONIC TRANSMITTER AND RECEIVER
Fig. 8: Making the script start at boot time
Fig. 8: Making the script start at boot time

$ sudo update-rc.d picam default

The script will now start and shut down along with the Raspberry Pi. We can also control it manually. That is, to stop the script, use the command:

/etc/init.d/picam stop

To start the script, use the command:

 

/etc/init.d/picam start

Method 2: Using motion software. To install motion software, use the command below (also see Fig. 9):

Fig. 9: Installing motion software
Fig. 9: Installing motion software

$ sudo apt-get install
motion

The standard motion packages do not yet work with Raspberry Pi camera. For that we have to install the special binary code known as motion-mmal. So install following dependencies (also see Fig. 10):

Fig. 10: Installing all the dependencies
Fig. 10: Installing all the dependencies

$ sudo apt-get install -y libjpeg62
libjpeg62-dev libavformat53 libav
format-dev libavcodec53 libavcodec-
dev libavutil51 libavutil-dev libc6-
dev zlib1g-dev libmysqlclient18
libmysqlclient-dev libpq5 libpq-dev

After installing all the dependencies, download motion software from the link:

https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz

Extract it using the command (also see Fig. 11):

Fig. 11: Extracting the folder
Fig. 11: Extracting the folder

tar -zxvf motion-mmal.tar.gz

This will extract the motion application as well as a configuration file. Run the extracted motion application along with its configuration file using the command (also see Fig. 12):

Fig. 12: Running the motion application
Fig. 12: Running the motion application

./motion -n -c motion-mmalcam.conf

While motion application is running, open the browser and type the IP address of your Raspberry Pi with the 8081 port (for example, 192.128.2.79:8081), as shown in Fig. 13, to see the live streaming video.

Fig. 13: Streaming video
Fig. 13: Streaming video

When camera detects the motion it will also capture the image and store it in Raspberry Pi Home folder, as shown in Fig. 14.

Fig. 14
Fig. 14

The author is a B.Tech (electronics and communication) from GGSIPU, New Delhi

LEAVE A REPLY