Home / Tutorials / Raspberry Pi Tutorial / How to Use a Web Cam with Raspberry Pi

How to Use a Web Cam with Raspberry Pi

The Raspberry Pi comes with a camera connector on board. But if you don't want to buy the official camera and use a web camera instead, you can! I'll show you how to display a video from the web cam on a web server hosted by a Raspberry Pi

For this tutorial, I used Logitech C270 web camera. This camera is directly supported by Raspberry Pi. You can use any other web cam that is listed here.

Software Requirements

First, we download mjpg-streamer:

We need libjpeg and cmake as well:

You should now have the mjpg-streamer folder. Go to mjpg-streamer-experimental folder and run make and install:

That installs the mjpg-streamer to the Raspberry Pi.

Embedding Video to Web Page

First of all, we need to know the name of the web camera. Go to dev and look for videox where x is any number. For example, mine's video1

Next, we create a script that would run the video stream continuously in the background. On root, create a file named stream.sh

Then paste the following:

This is assuming that your web camera name is video1.

Run the script using the following commands

Now its time to embed the video to a web page. If you haven't installed Apache, do this:

After installation of Apache server, CD to /var/www/html. In there you'll see a file named index.html. Delete this file:

Then create a new index.html file

And paste the following:

Here I used because that's my Raspberry Pi's IP address. You should replace that with your own board's address or use raspberrypi.local.

Save the index.html file and open the IP address of the Raspberry Pi using your preferred browser. Here's what mine looks like:

Raspberry Pi Web Camera

That's it! You can now create cool camera applications like image processing or camera robots.

Check Also

Uploading Camera Images from Raspberry Pi to Website

For those who are looking to work with images on their projects, the Raspberry Pi …

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.