Raspberry Pi As World Webcam Server

Biswajit Das


While it is not possible to always keep an eye on your homeefy tested55 or business while you are away we can make a world webcam to watch only important incidents, with a lower-cost solution. Presented here is a Raspberry pi server that can monitor and transfer data for you to access anywhere around the globe.

Traditional wireless CCTV cameras are inexpensive but anyone with a wireless receiver can view your signal and video feeds. On the other hand, IP cameras are secure but can be quite expensive, and usually the video quality is poor, unless you go for a very expensive model.

Raspberry Pi (or Raspi) is a credit card size computer that has the capability to become a camera security system along with an inexpensive webcam (Logitech in this case), a wireless Wi-Fi module and an optional battery pack. With these you can make a remote, motion activated camera costing lesser than those available in the market.

Fig. 1: Raspberry pi server: Raspi world webcam
Fig. 1: Raspberry pi server: Raspi world webcam

The raspberry pi server is based on motion software, which enables the webcam to detect motion and start recording images as well as videos. A script written in Python then directs the mail component running on Raspi to send email notifications with attached images and videos to the pre-defined email address. This email is sent every time any motion is detected by the camera.

Raspi is perfectly equipped to turn your USB based webcam into a functional IP webcam that can be accessed from anywhere with an Internet connection.

In this project, the webcam is hidden inside a door so it can be used to see people as they come and go. When motion is detected, a notification email is sent to you with attached images and videos. Thus, you can track any movement and get the information in a pre-defined email address anywhere in the world.

Functional diagram of Raspi as the world webcam is shown in Fig. 1.


Get the software ready. To start, you need Raspi with an Internet connection. Next, update it to ensure that it has all the latest software and drivers. Run the command given below, in the terminal, to update the operating system (OS) installed on Raspi:

[stextbox id=”info”]$ sudo apt-get update
$ sudo apt-get upgrade[/stextbox]

Install software Motion. This is a program that monitors video signals from cameras and can recognise any changes in the videos or images being captured by the camera.

The program is written in C language and is made for nix based OSes. Motion is a command line based tool whose output can be image files or mpeg video sequences. It is ideal for keeping an eye on your possessions, keeping only those images that are important and useful.

In this project, we report the following motion features:

1. Detect motion defined by the number of changed pixels
2. Take pictures and video recordings, store these and send by email
3. Make video recordings and store them sending by email
4. Run the following command to install Motion:
$ sudo apt-get install motion

Run the following command to find out if the camera attached to Raspi has been detected by the OS or not:

 [stextbox id=”info”]$ lsusb[/stextbox]

Your camera must be listed as a USB device. If not, get it to work properly before proceeding further. Next, configure Motion.

Configuring Motion

Motion configuration files are generally located in directory /etc/motion. We only need file motion.conf. Create a folder by the name motion using the following command:

 [stextbox id=”info”]$ sudo mkdir /home/pi/motion[/stextbox]

Copy configuration motion.conf file to it using the following command:

[stextbox id=”info”]$ sudo cp /etc/motion/motion.conf /home[/stextbox] [stextbox id=”info”]/pi/motion/[/stextbox]

Create another folder media under folder motion using the following command:

[stextbox id=”info”]$ mkdir /home/pi/motion/media[/stextbox]

media folder will contain captured images and videos.

Capturing video and sending emails as attachment

In motion configuration file (motion.conf) there is a lot of inline documentation, and majority of options are self-explanatory (for example, resolution of pictures/videos). Open motion.conf file in a text editor using the following command (you may copy motion.conf file provided with this article):

 [stextbox id=”info”]

$ sudo nano /home/pi/motion/




Make changes to the configuration file such that it can capture videos, save these in media folder and email these to the pre-defined email address. Given below is the list of parameters to be configured in motion.conf file.

target_dir /home/pi/motion/media [by default is “target_dir /tmp/motion” ]

movie_filename myvideo [by default is “movie_filename %v-%Y%m%d%H%M%S”]

on_movie_end python SendMyVideo.py %f [by default is “on_movie_end value”]

In the above configuration, we have used Python script to send emails, which get executed when the captured movie ends.

Script SendMyVideo.py is a Python script that is used to send emails with movies as attachments. Copy the script in /home/pi/motion folder.

Make necessary changes in Python script. Change the text given below with your email credentials, which you will use to send emails:

USERNAME = “[email protected]
PASSWORD = “examplepassword”

Change the email ID in sendMail( [“recever’s email ID here”] with the ID of the person who will be receiving the video clips.


In the Python script we have used Gmail as the SMTP server for sending emails. You can make necessary changes to the script in the SMTP section if you want to use any other SMTP server.

Configuration of the system is now complete. Start the world webcam by simply navigating to the directory and starting Motion using the command given below:

 [stextbox id=”info”]$ sudo cd /home/pi/motion[/stextbox]

and type

 [stextbox id=”info”]$ sudo motion[/stextbox]

Motion takes the local configuration file for execution. Videos will be saved in the sub-folder media. In addition, emails will be sent as configured with attached videos (myvideo).

Capturing photos and sending email as attachment

We can use the system to send images in place of videos. The script SendMyPicture.py is a Python script that is used to send emails with pictures as attachments. Copy the script in /home/pi/motion folder.

Make necessary changes in Python script for it to work in your environment. Change the email credentials as was done for SendMyVideo.py script for sending videos.

Make necessary changes in motion.conf file as given below:

Search for #on_picture_save python SendMyPicture.py

Uncomment it by removing #

Comment on_movie_end python SendMyVideo.py %f by adding #

Change command snapshot_filename %v-%Y%m%d%H%M%S-snapshot with lastsnap %v-%Y%m%d%H%M%S-snapshot

Start Motion using the command $ sudo motion by going to the /home/pi/motion

With the above configurations, Raspi will be configured to send videos and images, which are being captured by the webcam by sensing motion.

Scripts can be modified to do different tasks—we leave that for you to experiment with!


Biswajit Das was manager-R&D, EFY Labs till recently.


  1. Comment: My webcam can’t be read by the OS and whenever I type the isusb it doesn’t recognise the command, am using raspberry pi 1 model B. I need ur reply ASAP thanks


Please enter your comment!
Please enter your name here