Print this Page

Trust Webcam

The Raspberry PI is perfectly equipped to turn your USB based web cam into a fully functional IP web cam that you can have lots of fun with, from there you could use tools such as Python to make your project more unique. As a simple configuration, we will configure a web cam that can be accessed from anywhere with an internet connection.

1. Get the software ready

Type in the following in the command line to make sure everything is up-to-date on the Raspberry Pi.

sudo apt-get update
sudo apt-get upgrade

Now we need to install the software, we are going to be using an application called Motion, this will do a few things  including accessing the USB cam, getting the images, and streaming them via a built in web server. As the name suggests it will also track and trigger events on motion been detected in the video frames (more on that later).

sudo apt-get install motion
2. Plug in your web cam

So now the software is on there it’s time to plug in the web cam and ensure that everything is working, ensuring that you plug it into the powered hub, and then into the PI. Otherwise the webcam will not get enough power to turn on.

When plugged in type the “lsusb” command, you should see a line there with your web cam manufacturer, that proves that you have the basic connectivity working.

Bus 001 Device 002: ID 04ea:1142 Microsoft Corp.
3. Configure the software
sudo nano /etc/motion/motion.conf

In here there are a few basic changes that you need to perform:

  • Daemon = change from OFF to ON
  • webcam_localhost = change from ON to OFF
4. Start the software

To ensure that the motion service will actually start as a daemon we need to change another configuration setting, so enter the following:

sudo nano /etc/default/motion

Then change the value of “start_motion_daemon=no” to “yes”

Finally you can start the motion service to stream the web cam images

sudo service motion start

Then after about 30 seconds browse to the new web interface, which should be at the below URL (where is your Raspberry PI’s IP address).

To find your Pi`s IP address type ifconfig in a command terminal. Under eth0 you should see an address similar to: inet addr: which is the Pi`s IP address.

5. Final Tweeks

Web Port

You could change the web interface port to 80 (from the default 8081), so that you can just browse to the IP address without having to put :8081 at the end. To do this, type

sudo nano /etc/motion/motion.conf

And then change “webcam_port 8081″ to “webcam_port 80″, save the file, and restart the motion service.

sudo service motion restart



2) Scanning QR Codes

You can use your Webcam to scan QR Codes with the help of a tool such as zbar tools. To use zbar tools, all you need to do is install it by typing:

sudo apt-get zbar-tools

Now verify how your webcam shows up by typing:

ls /dev/video*. You should get something like: /dev/video0. Now type the following command, replacing 0 with the number your video webcam showed at, and the zbarcam tool will show up
zbarcam /dev/video0 

Provided that the camera is in focus, it should at this point be able to scan qr codes quite easily. Try to point it out at different qr codes and you should get the output in the terminal. You can check this on codes generated on the screen or on printed qr codes.

To generate a qr code, you can use a free online tool. is a good one to start with. You can select what type of output it gives: a message, a website, or any other option, and then hit “Download” to get the .png file with the qr code in your desired location. Once you have this, go to the terminal and install the ImageMagick tool by typing:

sudo apt-get install imagemagick

Once this has been finished you can view the barcode by typing (where you replace qrcode with the name of your image):

display qrcode.png

This now displays the qrcode on the screen. You can now point the web camera to the qr code and, once it is in focus, it will read it and will display the output in the terminal.

Permanent link to this article: