Capturing Images with USB Camera, Wi-Fi and Raspberry Pi

By Somnath Bera


Save the file with ctrl+o command. Exit Nano using ctrl+x command. Close it and go back to the terminal window.

Note that, the webcam has a versatile software, with an ability to continuously ftp the captured image to a remote server, where the main webpage may be the host. But, in this case, we have made local = 1, which means that we will host it on Raspberry Pi’s Apache server page (var/www directory) itself.

The delay = 0 means the cam will take pictures non-stop. Since this will put a lot of load on the tiny Raspberry Pi board, a delay of five (means, taking one snap every five seconds) will be more justified for Raspberry Pi.

Checking the working of Apache server

We will now check whether Apache web server is working or not. In the Raspberry Pi computer, open a Midori browser page and enter the address as:

[stextbox id=”grey”]http://localhost[/stextbox]Apache will open a page, indicating the server is up-and-running (even though there is no content page available in the server). So far, so good. Now, we have to see whether the same page is available over wireless or not.

Before that, we have to know the IP address of our Raspberry Pi board (mine is a DHCP by my wireless router).

Issue the following command at the terminal window:

[stextbox id=”grey”]

[email protected]:/$ifconfig

[/stextbox]This will give details of the IP addresses of the wired as well as the wireless network of Raspberry Pi board. Look out for WLAN configuration—WLAN IP address of my Raspberry Pi board as assigned by my router is So, I enter the following address in the address bar of the browser on my laptop:

[stextbox id=”grey”][/stextbox]The same page opens up in my laptop. This confirms that Apache is up-and-running on Raspberry Pi board.

Automatic capturing of images

Open the terminal window and enter the following command:

[stextbox id=”grey”][email protected]:/$sudo webcam /etc/
webcam.conf &[/stextbox]The last ‘&’ command means the process will execute in the background. Now, go back to a remote laptop and enter the following address in the browser address bar (To stop the webcam, use ctrl+c command or find out process ID number and then kill it by $sudo kill–9xxxx, where xxxx is the process number.):

[stextbox id=”grey”][/stextbox]A still-image facing the camera will now appear on the top-left corner of your laptop. This confirms that the webcam is working. You may try to open the same page in Midori browser on Raspberry Pi, but it may take several minutes to open, as most of its resources are busy handling webcam images. Do not worry; the page will open on the remote laptop quite comfortably.

Change the direction of the camera and refresh the browser on your laptop, and the image will change. Unless the browser window is refreshed, the picture will not change.

Now, we will create an automated page-refresh in Raspberry Pi itself.

Automated page-refresh from Raspberry Pi

Let us now use Nano to create a simple html page in /var/www directory of Raspberry Pi. Note that, /var/www is an Apache document root directory. Whatever we write here will be available, to view, from any PC connected to the network.

 [stextbox id=”grey”][email protected]:/$ sudo nano /var/www/
<h2> My Raspi Webcam </h2>
<img src=”webcam.jpg” width=”320”
</html>[/stextbox]Save using ctrl+o and exit using ctrl+x keys on the keyboard. Now, go to the remote laptop and open the page

The image will be auto-refreshing every second now. But, this may be a little irritating to the eyes, so we may need to enter a delay factor here. In the webcam, html CONTENT=”0” can be made to CONTENT=”5” for a more soothing refresh once in every five seconds.

You can strip Raspberry Pi board from the mouse, keyboard and monitor, and the webcam will still work non-stop—such is the power of Raspberry Pi and Linux.

Complete automation

Now, how about an automated script? So that, every time you boot or even before login, Raspberry Pi will fire-up the webcam command.

You can get rid of the monitor, keyboard and mouse from Raspberry Pi board. For that, we will put the command in /etc/rc.local file, and every time, on boot up, the webcam will start. Open a shell script file in /home/pi and enter the following command:


  1. I tried the above steps
    Dedian apache works fine on both on my rpi and laptop but when I try
    Opening the webcam server that is
    httpp:// or
    The result it gives is
    404 error url not found
    Plz help as soon as possible

  2. I also attempted to open the webcam server and got the “404 error url not found”. I have gone through many guides and don’t have any positive outcomes. Kindly assist


Please enter your comment!
Please enter your name here