Raspberry Pi: Vocal Intruder Warning System Project – Part 2

0

Raspberry Pi camera in hand, Vincent has updated his brilliant warning system project to take snapshots of intruders.

I have recently purchased one of the fantastic Raspberry Pi Camera modules. The camera costs around £20 and plugs into one of the special sockets on the Raspberry Pi. This socket connects straight into the Graphics Card (GPU) so it has excellent response times.

To take advantage of the Raspberry Pi camera I have added some code to my original Vocal Intruder Warning System Project that will take a still image each time somebody moves past the PIR sensor.

What you will require

Getting Started

For this project I will assume you have already followed the original vocal intruder project, so will only cover the extra setup required to get the camera working in the project.

First ensure your camera is connected as per the official instructions and video.

Adding the new Python librarys

On the Raspberry Pi, either via SSH or directly connected, enter the following commands:

When the module has finished installing then make a copy of your original code:

Now open the new copy of the code and modify as follows:

Remember to save your code and exit nano:

CTRL+O
CTRL+X

What’s changed

Line 21 & 22 : Here we are importing the new Python camera module code. This will allow us to capture images directly with python code.

Line 25: Here we are turning on the camera and telling our project to be ready to take an image.

Line 61 & 62 : We are getting the current time and date after motion has been detected by the project. I will stop here and go into some detail of line 62′s code.

Line 62 Detailed: We are creating a text string called “timestr” and then storing the date and time in the format “20140318-171725″. If you wish you can simply flip this around by changing the line to:

This would give “171725-20140318″ or if you change it to:

You would now get “17725018032014″

You can play about with this code until you are happy with the output.

Line 64 & 65: Since my module is upside-down, I need to add these two lines of code to make sure the image that is saved is the correct way up. Experiment with changing either or both from “True” to “False” to ensure your images are correct.

Line 66 : Now we take a picture and save it with a file name of “image20140318-171725.jpg”. The time stamp is added by breaking out of the string and adding in the string we set earlier.

The rest of the code is unchanged.

Running the project

Enter the following on the command line to kick it off:

To stop the code running at any time – press CTRL+C on your keyboard.

Now your code is complete. If you wish to view the images your project captures you can use a tool like FileZilla to access the Raspberry Pi and take the images from the project onto a PC or Mac. I will be back soon with a final follow up to this that will add some extra code to email the files to you.

Share.

About Author

Vincent is an IT Consultant who has been passionate about technology since lower school. He likes to pass this passion on to others through his posts.

Tell us what you think!

x
The ClassThink Guide to Managing iPad in Education
Available on iTunes Soon!

If you'd like us to let you know when our guide is available, pop your email below to sign up to our edtech newsletter:

Subscribe to our newsletter