Raspberry Pi as low-cost HD surveillance camera

FeaturedContest Winner
Picture of Raspberry Pi as low-cost HD surveillance camera
This instructable describes how to build a surveillance cam based on a Raspberry Pi micro-computer which records HD video when something moves in the monitored area. Live picture can be viewed from any web browser, even from your mobile while you're on the road.
What you will get:
  • See live stream in any web browser from anywhere
  • Record any motion into video file
Usually, such a cam will cost you around US$1.000, but with the result from this instructable, you will get such a cam for only about US$120.
Remove these adsRemove these ads by Signing Up

Step 1: Background

Picture of Background

Have you ever heard of Raspberry Pi? It's a low-cost micro-computer that is able to run Linux and has endless extension possibilities. It cost only about US$35 and opens up endless possibilities of what you can build with it. The official website can be found at

Step 2: Hardware components

Picture of Hardware components

We need some hardware for this project. This is a list of the major things we need:

  • Raspberry Pi Model B: This is the larger model of the Raspberry computer system with 700MHz and 512MB Ram. It supports HD video. You can easily order it from i.e. here. Cost: about US$40. You could also use the Raspberry Pi Model A which is slightly cheaper and consumes less energy. Stefan Knight has written an excellent article on how to run this whole project on a model A.
  • A housing for the camera: you don't need to buy a high-price-housing for your Raspberry. There are loads of very cheap fake security cameras available which perfectly fit our needs here. Search the web for "surveillance camera dummy" and you will find loads of housings for your new camera for only a few dollars. I.e. this one will do the job: for only US$9. We have ordered this camera housing for about 20€ in Germany that had enough space for all the components: You can use any camera housing, but only be careful about the size of the housing so that the Rasperry board will fit in there. The dimensions of the Raspberry board are 85.6 x 53.98 x 17 mm (approx 3.37 x 2.13 x 0.67 in).
  • Power supply: The Raspberry computer does not come with any power supply, you have to get one on our own. Any power supply with a micro-USB plug can do the job as long as it supplies at least 1A of power. We have ordered such a power supply which already has a micro-USB plug for about US$10
  • SD card: as the Raspberry Pi does not have any storage on board, you need to add some so that you can install and run the operating system for this device. Any SD or microSDHC should do the job, but we recommend using a Class 10 SD card. It's only around US$7
  • To connect this cam to your network, you also need some kind of network connection. One possibility is to use a LAN connection, but you would need to put LAN cable to the point where you want to mount the camera. A better alternative is such a WiFi USB adapter for only about US$10
That's all: for about US$120 we have all the hardware we need to build this HD surveillance cam.

Step 3: Install Raspbian

At first, you should install the OS and software to the Raspberry Pi before mounting it all together. An OS is the basic operating system software that tells the Raspberry hardware what to do. Linux is perfect for this. We have chosen Raspbian, as it's one of the most advanced OS for the Raspberry with loads of help and tutorials on the internet.
You need to prepare the SD card to be able to run Raspbian on the Raspberry: this excellent tutorial from Adafruit will explain the necessary steps.
Now temporarily connect your Raspberry Pi board to LAN cable, a monitor (HDMI TV works out of the box, but a HDMI-to-DVI cable like this will do the job as well) and a USB keyboard for the basic setup.
Insert the prepared SD card with the Raspbian installer on it and attach the power supply.
The Raspberry should boot up and guide you through the setup process as explained in this Adafruit tutorial. After this, you should have a basic Raspbian OS running.
Be sure to enable SSH in Raspbian so that you are able to control the Raspberry device also when there is no monitor and keyboard attached. And you should also enable the camera from the Raspbian setup menu so that we can use it for motion detection.
Now make sure your RPI is up to date:

sudo apt-get install rpi-update
sudo rpi-update

And also update all packages:

sudo apt-get update
sudo apt-get upgrade

Step 4: Connect via SSH

Picture of Connect via SSH

Now that the basic setup is done, you should connect to your Raspberry device from your computer. You can connect to Linux console from any computer in your local network and control it like you where sitting directly in front of it. This is very important as once mounted far away from your desktop, you need to be able to make updates and change the configuration of this camera any time later without the need to detaching it from the wall and bringing it back to your desk.

Remember that this cam is not just a dump cam device but a very powerful computer with Linux OS running on it. It's not limited to what we explain in this article now; it will follow any development in software so that you will be able to install updated software and more modules any time later.

First, you need a software to connect to the Linux console on the Raspberry. For Windows, you will need the extra (free) software PuTTY. Download it from the PuTTY website, install it and connect to your Raspberry Pi device:

From now on, you don't need any monitor and keyboard attached to the Raspberry anymore.

Step 5: Enable WiFi

If you want to run this camera with a WiFi USB dongle (like we've suggested in step 2), you will need to do some quick additional steps to make WiFi work on the Raspberry:
From the console (PuTTY window), edit the network properties of the Raspberry:
sudo nano /etc/network/interfaces 
Now add these lines at the end of the file (or change existing lines to match these):
allow-hotplug wlan0 
iface wlan0 inet dhcp 
(Fill in the SSID and password for your WiFi network)
Reboot the Raspberry with this command and see if it correctly connects to your WiFi network:
sudo reboot  

Step 6: Put the hardware together

Picture of Put the hardware together
Now it's time to assemble all the hardware components together into the housing. Depending on the housing, this should not be a too complicated job. Be sure to mount the Raspberry board safely so that it doesn't tumble around in the housing.
As our housing had a very large glass window at the front, we have closed it with a black paper with a hole in it. This has the advantage that the "tech" of the camera is not visible anymore. If you like the camera recording led to be visible, don't cover it. Whenever the camera is detecting any motion or is recording, the led light will glow in a very bright red.
You can also turn off the camera red LED by adding this line to /boot/config.txt:


Step 7: Installing the motion detection software

A very good (and free open-source) motion detection/surveillance software with many configuration options is motion.
We now need to install it using the command line (log in to your raspberry as user "pi"):
sudo apt-get install motion 
Some packages will be installed in the installation process; just type "y" to proceed with the installation.
As the current version of motion does not (yet) support the Raspberry camera module, we need to download and install a special build with support for this camera module.
cd /tmp 
sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
And now you need to unpack the downloaded file to the /tmp directory:
tar zxvf motion-mmal.tar.gz  
After this unzipping, you now need to update your installed motion with the downloaded build:
sudo mv motion /usr/bin/motion
sudo mv motion-mmalcam.conf /etc/motion.conf  
You also need to enable the motion daemon so that motion will always run:
sudo nano /etc/default/motion
and change the line to:
We're pretty sure that the official build of motion will shortly also support the Raspberry camera module as well.
A very important command to edit the motion configuration file is
sudo nano /etc/motion.conf  
Note: in the standard motion installation, the motion.conf is in /etc/motion/, but in the special motion-mmal build from dropbox-url (see above) it's in /etc/. If you follow this tutorial with all steps, this is no problem at all.
Be sure to have the file permissions correct: when you install motion via ssh while being logged in as user "pi", you need to make sure to give the user "motion" the permissions to run motion as service after reboot:
sudo chmod 664 /etc/motion.conf
sudo chmod 755 /usr/bin/motion
sudo touch /tmp/motion.log
sudo chmod 775 /tmp/motion.log  
We've made some changes to the motion.conf file to fit our needs. Our current motion.conf file can be downloaded here. Just download, unzip and copy the containing motion.conf to /etc/motion.conf if you would like to use the exact config options we describe below.
Some of the main changes are:
Make sure that motion is always running as a daemon in the background:
daemon on 

We want to store the logfile in /tmp instead (otherwise autostart user won't be able to acces it in /home/pi/ folder):

logfile /tmp/motion.log
As we want to use a high quality surveillance video, we've set the resolution to 1280x720:
width 1280
height 720 
We don't need real-time video, 2 pictures per second are totally ok for our needs:
framerate 2 
This is a very handy feature of the motion software: record some (2 in our configuration) frames before and after the motion in the image was detected:
pre_capture 2
post_capture 2 
We don't want endless movies. Instead, we want to have max. 10 minutes slices of the motion videos. This config option was renamed from max_movie_time to max_mpeg_time in motion. If you use the motion-mmal build, this one will work. If you get an error 'Unknown config option "max_mpeg_time"' either change this one to max_movie_time or make sure to really use the motion-mmal build as shown above.
max_mpeg_time 600 
As some media players like VLC are unable to play the recorded movies, we've changed the codec to msmpeg4. Then, the movies play correctly in all players:
ffmpeg_video_codec msmpeg4  
Enable access to the live stream from anywhere. Otherwise only localhost (= the Raspberry device) would be allowed to access the live stream:
stream_localhost off 
If you want to protect the live stream with a username and password, you should enable this:
stream_auth_method 2  
stream_authentication SOMEUSERNAME:SOMEPASSWORD 
All configuration parameters are explained in detail in the motion config documentation.
After your changes to the motion.conf, reboot the Raspberry:
sudo reboot  
After the reboot, the red light of the camera module should be turned on, which shows that motion currently is using the camera to detect any movement.

Step 8: Save videos on Windows shared folder

As the SD card of the Raspberry Pi is a pretty limited resource, we've decided to let the Raspberry cam store the videos on one of our Windows Servers. This is pretty easy:
First share a folder from some Windows machine. Just follow some guides on the internet if you've never shared a folder from a Windows machine before.
Then open the fstab configuration on your Raspberry from a PuTTY console or directly from the device:
sudo nano /etc/fstab  
Now add an extra line with the configuration of your Windows network shared folder:
//YOURSERVERNAME/YOURSHAREDFOLDERNAME /mnt/camshare cifs username=YOURSHAREDFOLDERUSERNAME,password=YOURSHAREDFOLDERPASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0 
Be sure that the user has the correct permissions to save files to that shared folder.
After a reboot, the Raspberry should have an extra folder /mnt/camshare mounted to the Windows shared folder. You should now set in your motion.conf:
target_dir /mnt/camshare 
so that motion saves all movies to the shared folder on the Windows machine.

Step 9: Fix motion autostart

Picture of Fix motion autostart
We had some trouble that motion was not automatically started on a reboot of the Raspberry. We've found out that this was because the mounted folder of the Windows machine was not yet ready when motion tried to access it.
A very quick fix solved our problem:
Just edit the motion file with
sudo nano /etc/init.d/motion 
and add the line
sleep 30 
to the start-sequence.
Our changed /etc/init.d/motion script can be downloaded from here.

Step 10: Mounting the camera

Picture of Mounting the camera
After all these steps, you can finally mount the surveillance camera to the destination point.
Some helpful hints:
  • Be sure to place the power supply in a dry and safe place
  • Keep an eye on the WiFi signal: if you mount the camera out of range of the WiFi, it won't be able to send any live video nor save any motion videos

Step 11: Accessing the live stream

Now you can access the live stream from the camera from any browser via the url http://IPADDRESSOFRASPBERRY:8080
Where 8080 is the port that we've configured for our stream in the motion.conf file. See your own configuration setting "stream_port" in motion.conf for the port.
We've found out that Google Chrome 30 (not even on iOS) wasn't able to play this stream directly due to a bug in the underlying Chromium project.
A workaround for this is to create a simple html file that contains one large image with the stream-url of the camera. See the file cam.html from This way, Chrome can show the live stream as well. Let's hope that Chrome will fix this issue in their browser.
But other browsers like FireFox, Safari and even VLC media player was able to show the live stream of the camera.
We were not able to make the live stream work in Internet Explorer as it doesn't support Motion JPEG. Kenneth Lavrsen (the maker of motion) has described workaround for live stream in Internet Explorer here.

Step 12: Access live stream from anywhere

Picture of Access live stream from anywhere

To make the live stream accessible from anywhere, you will need to enable some kind of dynamic domain services to your local network. This will enable you to always be able to connect to your local IP address from the outside even if your local IP address changes (over here in Germany, every private DSL ip address changes every 24 hours).
Such a (free) service enables you to access your Raspberry from anywhere even if your ip address changes. A very good service we're using for some years now is They have some free services and are integrated in many routers.
Once you have set up the dynamic ip url, you can access the camera stream from anywhere in your browser (i.e. http://YOURDYNAMICDOMAIN:8080).
And this also works from the browser on your mobile device.

Step 13: Next steps

There are a thousand things you can do with such a surveillance cam basic setup now. How about sending Growl notifications when some motion was detected? This guide explains how to add this functionality easily.

Or you could easily add a temperature-sensor to the cam. It's only a few bucks and can be integrated very easily.
We're currently working on integrating the live stream into MediaPortal server so that we can switch to a TV channel to see the live stream from the cam in our office.

If you want extra security, you could also add a battery pack to the camera. Be sure to buy one that is able to charge simultaneously while powering the Raspberry. This would enable you to detect if some bad guy cuts the power strips of your camera and send some alert messages to you (i.e. SMS or email) including the video of the disturber.

What are you going to add? Let us know!

1-40 of 199Next »

If you have permission problems (myfopen: Error opening file etc) use motion process uid to mount filesystem.

//YOURSERVERNAME/YOURSHAREDFOLDERNAME /mnt/camshare cifs username=user,password=pwd,uid=motion,iocharset=utf8, file_mode=0777,dir_mode=0777 0 0

aeroflot9 days ago


This is a great tutorial but I can't get it to work for the life of me. I get about two seconds of images in my browser before I get the connection was reset. This is the log file I'm getting:

[1] [NTC] [EVT] [Sep 04 14:47:22] event_new_video FPS 2
[1] [INF] [ENC] [Sep 04 14:47:22] ffmpeg_open FPS 2
[1] [INF] [ENC] [Sep 04 14:47:22] ffmpeg_avcodec_log: err{or,}_recognition separate: 1; 1
- flag 48
[1] [INF] [ENC] [Sep 04 14:47:22] ffmpeg_avcodec_log: err{or,}_recognition combined: 1; 1
- flag 48
[1] [INF] [ENC] [Sep 04 14:47:22] ffmpeg_avcodec_log: Unsupported bit depth: 0
- flag 48
[1] [ERR] [ENC] [Sep 04 14:47:22] ffmpeg_open: url_fopen - error opening file /home/pi/motion/01-20140904144721.avi ... check access rights to target directory:
[1] [ERR] [EVT] [Sep 04 14:47:22] event_ffmpeg_newfile: ffopen_open error creating (new) file [/home/pi/motion/01-20140904144721.avi]:
[1] [NTC] [ALL] [Sep 04 14:47:22] motion_detected: Motion detected - starting event 1
[1] [NTC] [ALL] [Sep 04 14:47:22] motion_loop: Thread exiting
[1] [NTC] [STR] [Sep 04 14:47:22] stream_stop: Closing motion-stream listen socket & active motion-stream sockets
[1] [NTC] [STR] [Sep 04 14:47:22] stream_stop: Closed motion-stream listen socket & active motion-stream sockets
[1] [INF] [ALL] [Sep 04 14:47:22] motion_cleanup: Calling vid_close() from motion_cleanup
[1] [INF] [VID] [Sep 04 14:47:22] vid_close: calling video source cleanup
[1] [ALR] [VID] [Sep 04 14:47:22] MMAL Camera cleanup
[1] [DBG] [VID] [Sep 04 14:47:22] camera_buffer_video_callback: camera_buffer_video_callback - entry
[1] [DBG] [VID] [Sep 04 14:47:22] camera_buffer_video_callback: camera_buffer_video_callback - exit
[1] [DBG] [VID] [Sep 04 14:47:22] camera_buffer_video_callback: camera_buffer_video_callback - entry
[1] [DBG] [VID] [Sep 04 14:47:22] camera_buffer_video_callback: camera_buffer_video_callback - exit
[1] [DBG] [VID] [Sep 04 14:47:22] camera_buffer_video_callback: camera_buffer_video_callback - entry
[1] [DBG] [VID] [Sep 04 14:47:22] camera_buffer_video_callback: camera_buffer_video_callback - exit
[0] [NTC] [ALL] [Sep 04 14:47:22] main: Motion thread 1 restart
[1] [NTC] [ALL] [Sep 04 14:47:22] motion_init: Thread 1 started , motion detection Enabled
[1] [ALR] [VID] [Sep 04 14:47:22] mmalcam_start: MMAL Camera thread starting... for camera ( of 1280 x 720 at 2 fps
[1] [ALR] [VID] [Sep 04 14:47:22] mmalcam_start: MMAL Camera using video capture
[1] [NTC] [VID] [Sep 04 14:47:23] MMAL camera component created
[1] [NTC] [ALL] [Sep 04 14:47:23] image_ring_resize: Resizing pre_capture buffer to 1 items
[1] [NTC] [STR] [Sep 04 14:47:24] http_bindsock: motion-stream testing : IPV4 addr: port: 8080
[1] [NTC] [STR] [Sep 04 14:47:24] http_bindsock: motion-stream Bound : IPV4 addr: port: 8080
[1] [NTC] [ALL] [Sep 04 14:47:24] motion_init: Started motion-stream server in port 8080 auth Disabled
[1] [NTC] [ALL] [Sep 04 14:47:24] image_ring_resize: Resizing pre_capture buffer to 3 items
[1] [DBG] [VID] [Sep 04 14:47:24] mmalcam_next: mmalcam_next - start
[0] [DBG] [VID] [Sep 04 14:47:24] camera_buffer_video_callback: camera_buffer_video_callback - entry
[0] [DBG] [VID] [Sep 04 14:47:24] camera_buffer_video_callback: camera_buffer_video_callback - exit
[1] [DBG] [VID] [Sep 04 14:47:24] mmalcam_next: mmalcam_next - got buffer
[1] [DBG] [VID] [Sep 04 14:47:24] mmalcam_next: mmalcam_next - new buffer returned
[1] [DBG] [VID] [Sep 04 14:47:24] mmalcam_next: mmalcam_next - buffer loop completed
[1] [DBG] [ALL] [Sep 04 14:47:25] alg_labeling: Label: 2 (0) Size: 843 (88,0)
[1] [DBG] [ALL] [Sep 04 14:47:25] alg_labeling: Label: 3 (1) Size: 338229 (108,0)
[1] [DBG] [ALL] [Sep 04 14:47:25] alg_labeling: Label: 4 (2) Size: 21 (79,2)
[1] [DBG] [ALL] [Sep 04 14:47:25] alg_labeling: Label: 5 (3) Size: 130 (797,3)
[1] [DBG] [ALL] [Sep 04 14:47:25] alg_labeling: Label: 6 (4) Size: 21 (101,63)
[1] [DBG] [ALL] [Sep 04 14:47:25] alg_labeling: Label: 7 (5) Size: 636 (124,90)

BrianS110 days ago

This is great, thanks.
I'm trying to configure it to run a script once image has been saved.

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)

# To give the filename as an argument to a command append it with %f

; on_picture_save value

So instead of the last line, I have removed the ; at start and added:

on_picture_save /home/pi/

Is this correct? Or how should it look as the script isn't running for me. Thanks

fudjy19 days ago

Rather than connect to a Windows machine, I'm trying to mount a NAS device on my network (also a Raspberry Pi). When adding the following line, and then doing 'ls' in /mnt/camshare, the two files in the NAS do not show, suggesting that it isn't mounting correctly.

//NASPi/Storage/Camera1 /mnt/camshare cifs user=Matt,password=nexus,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

Any idea where I'm going wrong here?

BrianS1 fudjy10 days ago

Did you try running that command on its own outside of fstab?

You could run it using cron either if the fstab entry doesn't work. Thats what I did, and I'm using cifs also

JacobJ110 days ago

it says when i try to connect it couldn't connect to the server???? HELP!!!

Delovar11 days ago

Good day! Again, I have a problem. Video stream in my browser runs for a few seconds, and then disappears again. I do not know how can I fix it.

I lowered the resolution of 640 x 480, but it did not help.

Here is my log file:

[-1243011424] [NTC] [ALL] [Sep 03 02:27:56] motion_startup: Using log type (ALL) log level (ALR)

[1] [ALR] [VID] [Sep 03 02:27:56] mmalcam_start: MMAL Camera thread starting... for camera ( of 640 x 480 at 2$

[1] [ALR] [VID] [Sep 03 02:27:56] mmalcam_start: MMAL Camera using video capture

[1] [ALR] [VID] [Sep 03 02:28:04] MMAL Camera cleanup

[1] [ALR] [VID] [Sep 03 02:28:05] mmalcam_start: MMAL Camera thread starting... for camera ( of 640 x 480 at 2$

[1] [ALR] [VID] [Sep 03 02:28:05] mmalcam_start: MMAL Camera using video capture

[1] [ALR] [VID] [Sep 03 02:28:13] MMAL Camera cleanup

[1] [ALR] [VID] [Sep 03 02:28:14] mmalcam_start: MMAL Camera thread starting... for camera ( of 640 x 480 at 2$

[1] [ALR] [VID] [Sep 03 02:28:14] mmalcam_start: MMAL Camera using video capture

[1] [ALR] [VID] [Sep 03 02:28:22] MMAL Camera cleanup

[1] [ALR] [VID] [Sep 03 02:28:23] mmalcam_start: MMAL Camera thread starting... for camera ( of 640 x 480 at 2$

[1] [ALR] [VID] [Sep 03 02:28:23] mmalcam_start: MMAL Camera using video capture

Delovar13 days ago

Hello, I have problem again...

I can not see the video stream in browser. I did everything as it is written in the manual, but was told that they log on the work of the Motion

Tell me where the error?


GNU nano 2.2.6 File: /tmp/motion.log

[-1242847584] [NTC] [ALL] [Aug 31 21:08:56] motion_startup: Using log type (ALL) log level (WRN)

[1] [ALR] [VID] [Aug 31 21:08:56] mmalcam_start: MMAL Camera thread starting... for camera ($

[1] [ALR] [VID] [Aug 31 21:08:56] mmalcam_start: MMAL Camera using video capture

[1] [ERR] [ENC] [Aug 31 21:09:03] ffmpeg_open: url_fopen - error opening file /home/pi/01-20140831210902.$

[1] [ERR] [EVT] [Aug 31 21:09:03] event_ffmpeg_newfile: ffopen_open error creating (new) file [/home/pi/0$

[1] [ERR] [ALL] [Aug 31 21:09:03] myfopen: Error opening file /home/pi/01-20140831210902-00.jpg with mode$

[1] [ERR] [ALL] [Aug 31 21:09:03] put_picture: Can't write picture to file /home/pi/01-20140831210902-00.$

Thread is going to finish due to this fatal error:

[1] [ERR] [ALL] [Aug 31 21:09:03] myfopen: Error opening file /home/pi/01-20140831210902-01.jpg with mode$

[1] [ERR] [ALL] [Aug 31 21:09:03] put_picture: Can't write picture to file /home/pi/01-20140831210902-01.$

Thread is going to finish due to this fatal error:

[1] [ALR] [VID] [Aug 31 21:09:03] MMAL Camera cleanup

scavix (author)  Delovar12 days ago
Just read the error messages in the log: motion can't write to the /home/pi folder.
Just execute
sudo chmod 755 /home/pi
and it should work.
MarianaS113 days ago

Hi, there! Thanks man!! You really saved me! I saw lots and lots tutorials, but this one is the best. Just one question: is there any possibility to increase framerate? Even when I changed in motion.conf, it keeps record 2fps. I'd like to appear more "real-time". Any solution?

AndrewC119 days ago

This is a great project! I've burned through some commercial consumer-grade wifi cameras - they tend to not last very long...possibly a function of the weather and our Texas heat. I've even repaired them a couple times; replacing the IR LED array or even the wifi daughterboad. This will be much more easily serviced and debugged, though - really cool.

I went a little further by adding an IR LED array that I happened to have lying around (from previous repairs projects). It is similar to this one - - although I can't guarantee this is the same one - I got it a long time. A wide variety of these arrays are available - check the dimensions carefully to make sure it will fit in your enclosure. The one I had fit perfectly in the cylindrical camera body specified in the parts list, above (not the square one shown in the pics, BTW). I mounted the camera board right behind it and cut a short length of black plastic tube that fit in the center of the array to prevent back-scatter of light when the LEDs are on.

These arrays generally come with a built-in light sensor, so they only come on at night. They tend to run on 12V, so I use a 12V AC adapter, and a ripped the guts out of a $10 cigarette lighter USB adapter from Walmart (cheaper are available) and hard-wired it in much like described here: Be sure and get one that cranks out at least 1 Amp - I did have issues getting enough power to the RPi to power it and the Wifi dongle.

I'll post some pics here

scavix (author)  AndrewC118 days ago


Darwin23321 days ago

Howdy, I am a newbee, please help. In step 7 says

We've made some changes to the motion.conf file to fit our needs. Our current motion.conf file can be downloaded here. Just download, unzip and copy the containing motion.conf to /etc/motion.conf if you would like to use the exact config options we describe below.

I downloaded the zip to my windows 7 machine and I have putty connected to the RPI, how do I upload the 3files that are in the zip to the RPI???

Thanks for the great instruct able. Thanks for your help on this.

scavix (author)  Darwin23319 days ago

You could use wget to download directly to the Pi or just transfer the files using SFTP. Google will show you tons of tutorials on these two options.

Followed the instructions exactly - used your config file. The service is running, the light is on the camera (although it keeps going off and on every few seconds), but nothing is recording and the live view reports that "the server was reset while the page was loading". Anyone have any ideas?

More - the log indicates that it is responding to motion. Howvwer, no video files appear, and I'm not able to use the web interface.

scavix (author)  fourleggedostrich26 days ago
Please set the logging in motion.conf to ALL to get more messages/logging. Perhaps there's more information on the problem in the motion.log then.

Thanks - it appears the issue was with the Pi itself. I tried basic camera streaming, which also failed. Then tried the same card in a different Pi and it worked perfectly. Am now re-building this system with the new Pi, and see if it works.

Delovar28 days ago

Hello again,

I do not understand the next action:

In step 7 I carry out programming raspberry pi as user "pi" and and I adjust the different values in the sudo nano /etc/motion.conf

Further according to the manual says:

"Be sure to have the file permissions correct: when you install motion via ssh while being logged in as user "pi", you need to make sure to give the user "motion" the permissions to run motion as service after reboot"

sudo chmod 664 /etc/motion.conf

sudo chmod 755 /usr/bin/motion

sudo touch /tmp/motion.log

sudo chmod 775 /tmp/motion.log

I'm trying to load as user motion: su motion

But the system requires a password (screen in attach)

What was meant when the required load under user motion? What is the password for user "motion"?

scavix (author)  Delovar26 days ago
Use the motion.conf from our instructable or use sudo motion.conf to set the configuration parameters for your needs.

You don't need a password for user motion. Don't exec su motion. Just run the commands with "sudo" (i.e. "sudo chmod 755 /usr/bin/motion") and they will be executed as root user.
Delovar29 days ago


In Step 7, I'm trying to install motion: sudo apt-get install motion

First installation is correct, but after that when I write "Y" to continue installation, there are many errors. Example of errors in the attached screenshot.

I tried to go to the site, but it is not available and not pinged.

Tell what responsible for such errors?

scavix (author)  Delovar29 days ago
It really looks like the motion website is currently down. But this is not responsible for the 404 errors.
Please just execute:
sudo apt-get update
sudo apt-get upgrade
first and then try again. This should fix the 404 errors.
wagaboom1 month ago

For a remote location in Denmark i am looking for a remote camera that would offer live streams over web connecting to a 3G GSM network whenever there is movement.

Sounds like an easy enough task with all the IP Cams out there.

However: i found out you actually don't get an IP address in a mobile GSM network, so you can't use DynDNS to access the camera.
So, this would mean that the cam needs to stream it's images ITSELF to a server.

Does anyone have an idea for this problem-solving?

scavix (author)  wagaboom1 month ago
You could just make this camera uploading the video to an ftp server (see

Where could i get the source code for prebuilt binary in the archive?

Is it sufficient to just use the official svn code with the motion-mmalcam.conf from the archive?

beerhead5001 month ago

Would be interested if you could add a microphone for sound? Sort of like a baby monitor.

scavix (author)  beerhead5001 month ago

Interesting idea, thanks for that. We'll try to figure out how to add a microphone to this.

Hi. Increased log level to 9 and got the following. Doesnt seem to add any more clues.

pi@domoticzpi /tmp $ cat motion.log
[-1242827936] [NTC] [ALL] [Jul 28 21:38:23] motion_startup: Using log type (ALL) log level (ALL)
[-1242827936] [NTC] [ALL] [Jul 28 21:38:23] become_daemon: Motion going to daemon mode
[-1242827936] [NTC] [ALL] [Jul 28 21:38:23] become_daemon: Created process id file /var/run/motion/ Process ID is 2584
[-1242827936] [NTC] [ALL] [Jul 28 21:38:23] motion_startup: Motion running as daemon process
[-1242827936] [NTC] [ENC] [Jul 28 21:38:23] ffmpeg_init: ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
[0] [NTC] [ALL] [Jul 28 21:38:23] main: Thread 1 is from /etc/motion.conf
[0] [NTC] [ALL] [Jul 28 21:38:23] main: Thread 1 is device: /dev/video0 input -1
[0] [NTC] [ALL] [Jul 28 21:38:23] main: Stream port 8081
[0] [NTC] [ALL] [Jul 28 21:38:23] main: Waiting for threads to finish, pid: 2584
[0] [NTC] [STR] [Jul 28 21:38:23] httpd_run: motion-httpd testing : IPV4 addr: port: 8082
[0] [NTC] [STR] [Jul 28 21:38:23] httpd_run: motion-httpd Bound : IPV4 addr: port: 8082
[1] [NTC] [ALL] [Jul 28 21:38:23] motion_init: Thread 1 started , motion detection Enabled
[1] [ALR] [VID] [Jul 28 21:38:23] mmalcam_start: MMAL Camera thread starting... for camera ( of 1280 x 720 at 2 fps
[1] [ALR] [VID] [Jul 28 21:38:23] mmalcam_start: MMAL Camera using video capture
[0] [NTC] [STR] [Jul 28 21:38:23] httpd_run: motion-httpd/mmaltest running, accepting connections
[0] [NTC] [STR] [Jul 28 21:38:23] httpd_run: motion-httpd: waiting for data on port TCP 8082
[1] [ERR] [VID] [Jul 28 21:38:23] Failed to create MMAL camera component create_camera_component
[1] [ALR] [VID] [Jul 28 21:38:23] MMAL Camera cleanup
pi@domoticzpi /tmp $

Hi. As far as I can tell I have followed your guide to the letter. However, when I try to start the motion service I get the following:

pi@domoticzpi /tmp $ sudo service motion restart

pi@domoticzpi /tmp $ cat motion.log

[-1242229920] [NTC] [ALL] [Jul 28 20:29:26] motion_startup: Using log type (ALL) log level (WRN)
[1] [ALR] [VID] [Jul 28 20:29:26] mmalcam_start: MMAL Camera thread starting... for camera ( of 1280 x 720 at 2 fps
[1] [ALR] [VID] [Jul 28 20:29:26] mmalcam_start: MMAL Camera using video capture
[1] [ERR] [VID] [Jul 28 20:29:26] Failed to create MMAL camera component create_camera_component

[1] [ALR] [VID] [Jul 28 20:29:26] MMAL Camera cleanup

pi@domoticzpi /tmp $

Is there anywhere I should be looking to identify why motion failed to create the camera component?

StevenT11 month ago

how could i get the cameras to send me an sms when motion was detected, is there a program like growl for windows ?

cmcdowell72 months ago

For a $120 that's not actually a good deal considering that PTZ cameras
nowadays are expensive for a common folk like me. Anyway, I don't know much
about installations and anything technical is there any available Raspberry Pi
cctv camera that's a plug and play?

scavix (author)  cmcdowell72 months ago
Raspberry Pi is about making things yourself. The DIY is big part of the fun. I don't know of any prebuilt cctv cameras with Raspberry inside.
Wingspinner3 months ago

A few comments....

First, thank you scavix for putting up this very comprehensive tutorial. There are so many that people put up that never worked in the first place but your's actually does and it's well written. Thanks, nice job!

Second, I have a few suggestions for those of you having problems getting it going:

1. Start from an absolutely fresh install of Raspian. Don't re-use one you've been playing with. You'll avoid a lot of headaches if you start fresh so you are working from exactly the same starting point as scavix

2. Use a class 10 SD card. Despite the fact that Raspian can supposedly work with slower cards I've generally found that the slower the card the flakier things get.

3. My primary usage is as a security cam and I want the RPi to behave much like my Vivotek IP3130W IP cam. For that purpose I don't need large, super high-res videos or stills. I found more robust results by using a smaller frame size. There are several reasons for this but mostly it has to do with RPI processor performance and data bandwidth. The motion detection, the jpeg encoding, and network transfer are all done with the processor according to dozencrows, the author of the RPI patches to the motion package and this . The following resolutions are known to work without problems according to him:

352 x 288
512 x 288
640 x 480
768 x 432
768 x 576
1024 x 576

He says others may work but haven't been thoroughly tested. I've got three of these running at 640x480 at 5 FPS for weeks now with no lockups or reboots.

4. Related to bandwidth issue, if you point the output files to a RAM based file system response time and reliability go way up in my experience. Of course, you'll be limited as to how much video you can store but if you are using it for a security cam you don't need to have many huge, high-res captures just "the ones you need" (I'll address that next). I didn't want to make it complicated so I simply mounted /tmp on the tmpfs file system (ramdisk based). To do that add the line "RAMTMP=yes" in the file /etc/default/tmpfs. Use "sudo nano /etc/default/tmpfs" to edit the file. Then, in the "/etc/motion.config" file set "target_dir=/tmp" and "logfile=/tmp". Be aware that any files written to a ram based filesystem are lost if you power down or reboot so this may not be right for you.

5. There are a number of configuration variables that can be optimized for your particular needs. I want to minimize storage and bandwidth requirements but have nice looking real-time streaming so I've set the following:

framerate 2

# despeckle_filter EedDl

minimum_motion_frames 5

event_gap 10

max_mpeg_time 10

ffmpeg_variable_bitrate 5

stream_quality 75

stream_maxrate 5

All others set to either default values or what scavix has specified.

5. Lastly, I installed watchdog timer support which will automatically reboot the RPi if the processor hangs or if the file systems get full (this can be configured).

I hope these pointers can help. Good luck!

@Wingspinner, I totally agree with your comments about scavix's comprehensive tutorial. But I'm disappointed that the RPi cam module cannot use the it's full potential: 1080p with 30 fps. That's why I'm now using RPi Cam Web Interface:

Oh, one more thing. By the time I factored in all the costs of putting an RPI based IP cam together it really wasn't much of a savings over a good quality ready-made IP came. I have a couple of the Vivotek IP8130W HD cameras and I'm very pleased with their performance and reliability. Not only are they HD but they are very flexible in terms of setup and have excellent low-light and no-light performance. Best of all they can be had for around $170 so and RPi based camera with case, power supply, etc. etc is only $40-$50 cheaper. A lot of fun though!

nikkala3 months ago

This has been a great tutorial! But I have a one problem: As soon as there is any motion in front of my cam, the stream cuts off. How could I fix this? The red led of the cam is always on, and when there is any motion led goes off and stream wont work. Oh yes, and my pi is not saving any of my videos to my shared folder.

scavix (author)  nikkala3 months ago

In your motion.conf, set the log_level to 9. Then reboot your pi and see what the motion.log says.

This is the general procedure for any kind of problems. As motion will tell you in it's log file what it doesn't like.

nikkala scavix3 months ago

Thanks! It seems like I have messed up somewhere while creating a shared folder. After doing all the steps there is still no any folders like /mnt/camshare and the pi keeps saving pictures in the pi itself. After all I think my problem looks like to be the same as the guy below, Nikhil. So I have to keep on working on this...

/mnt/camshare folder is not created after performing all the steps,so m unable to record videos automatically to my shared folder .
Give me some advice, may be I have gone wrong somewhere
In step 7 after doing all steps when I reboot the system , the red light of the camera is not on i.e. It is still off.
So please help me out.
1-40 of 199Next »