Part 2 in this series is going to show you how to setup Raspberry Pi and Motion in order to snap a picture every 10 minutes or so.

If you haven’t already read Part 1 in this series to check out how to set up a Raspberry Pi temperature sensor with the DS18B20 sensor.

Having setup the temperature sensor and tested that it can read the temperature correctly, I can now move on to setting up our camera to capture an image of the weather every 10 minutes.

Fortunately I did have a spare web cam lying around but you could get away with spending a couple of dollars and getting a fairly cheap web camera that’ll do the trick.

Now to do this I am going to use a pretty cool piece of software called Motion. Motion is a piece of software which uses video4linux device to detect motion and can be used to take both videos and pictures. It also has a pretty powerful trigger action settings which allows you to run shell commands after/before a certain event in order to perform extra actions (eg Send an email or upload the video/picture). I will make use of these in the next part of this series in order to grab the current temperature after the image has been taken.

One of the cool things people have used Motion for is to make a basic home security system. Have a webcam pointed at the driveway or main entrance to your house and then have motion take a video or picture of anyone who approaches. Upload the video to a remote location and send you an email letting you know you have a visitor. Works quite well and for ~$50 is a cheap solution.

For now though I am going simpler. Tell Motion to take a picture of whatever the web camera is pointing at every 10 minutes and move the picture to our images folder (later used for the website I make). In my case I will be pointing my web cam out the window in order to see the weather.

Setup Raspberry Pi and Motion

Firstly, install and setup motion on the Raspberry Pi.

# Update and upgrade the Raspberry Pi
sudo apt-get update
sudo apt-get upgrade

# Install motion
sudo apt-get install motion
Bash

Then edit the config file.

# Tell the service to start in daemon mode
sudo nano /etc/default/motion
start_motion_daemon=yes

# Make these changes to the motion config file
sudo nano /etc/motion/motion.conf
daemon on
snapshot_interval 600
output_normal off
ffmpeg_cap_new off
target_dir /home/pi/motion/images
INI

The above changes made to the config are only a handful of the options you will see inside the file. The general idea of the changes I made are to turn off video recording and to tell motion to take a snapshot every 10 minutes and to then save the file to the images directory. Feel free to play around but these settings will get me doing what I need to do.

Start Motion on the Raspberry Pi

You probably want to start motion in debug mode the first time around just to make sure everything is as it should be.

sudo motion -n
Bash

This will display output to the screen and every 10 minutes you should see snapshots getting saved to the output directory.

Check the directory and download the images to make sure you are getting the desired output and if all is as expected you can now start the motion service.

sudo service motion start
Bash

That’s it! Raspberry Pi and Motion is now set up. Pretty easy and straight forward. Like I said though, this is one of the more basic uses of motion and it can be used to do a lot more. Have a play around and let me know what you come up with. I’m always interested!

The next part of this tutorial series I will be showing you how to write a python script which will be executed using the motion action trigger.

So stay tuned and as always you can follow me on twitter @JAGracie