Motion is the essence of the project. It is a wonderful program, which is easy to install and possesses a wide variety of functions that can be used to expand the project. The principle of Motion is the following: it constantly watches a stream of video and counts the amount of pixels that change the intensity. As soon as the change of the image exceeds a certain level (counted as the amount of changed pixels), a motion detection event is triggered. This event can be used for a number of different things.
As you may expect, the core motion detection is done by the software. Although a PIR sensor can be used as an alternative, Motion offers a lot of options for interfacing of other pieces of software and thus the flexibility. Installing Motion and complementing it with some code is how the project operates.
Before we proceed with installing Motion, we need to pre-configure the Raspberry Pi to a certain extent. This is our "to do" list for now:
In order to make the system more robust, it makes sense to set up the static IP,
since knowing of the IP adress is vital for the system to function.
The exact address of the Raspberry Pi may be different in your case, so in order to avoid confusion,
I will just refer to the address as
The configuration procedure for this part is best discussed here.
Before installation, it is good to make sure the Raspberry is up to date.
(If you use Linux, simply type
ssh PiIP in the terminal. In Windows, you may use PuTTy instead):
Now, let us download the program Motion. There is a good tutorial available
here. However, that link instructs to download Motion using
wget as a
.tar.gz file, which is later extracted. It did not work for me. That is why, I suggest you follow the
To install Motion, execute:
Then, make sure that all libraries are set in place.
By the way, several tutorials prompt to set
/etc/default/motion file. If you want to make Motion run in the background at all times, do it.
I don't, since I would like to be able to switch the program on and off extarnally.
The Motion program is installed. In order for it to function, we need to change the file permissions.
That makes sure that files can be read from, written to and executed correctly.
Finally, the essence of the program configuration. All that is done by writing lines into the
Consult the Motion documentation for all the options and experiment yourself. In my case, I edited the following lines:
Don't worry if the lines look a bit misterious. If you open the
the meaning of all the lines is explained in the supplied comments. As I wrote before, consult the documentation of the program and experiment yourself.
The last two lines, are sort of special add-ons of this project.
target_dir specifies the output directory of all the images and videos to be saved to, while
on_event_end supplies the expanson of the project regarding of
what to do with the pictures/videos once motion is detected. We will discuss
that extension on the next page. Note that I have written in capitals the names that will probably be different in your case.
The Motion program can be switched on by executing the following command in the terminal window:
For switching it off, use:
Oh! One more thing. Some tutorials instruct to set
disable_camera_led=1 line in
Obviously, you don't want the others to know that their presence has activated your camera (or do you?).
Personally, I prefer to wait with this kind of settings until the very end as it helps me with debugging.
If everything works correctly, you should see the camera LED shine red if you switch the Motion on. Furthermore, opening a web browser and typping
http://PiIP:8081 in the address field should display the real-time stream from the camera.
Checking the content of the
/home/USER/CAMERAPROJECT/INBOX directory should indicate the detected presence.
If not, check
/tmp/motion.log file for any error messages. Misspelled words or wrong paths/filenames are there to blame.