How to install a USB webcam in Raspberry Pi

Last updated on November 29, 2020 by Kristophorus Hadiono

Question: Can I use a standard USB-based webcam on Raspberry Pi? How can I check if my USB webcam is compatible with Raspberry Pi, and how can I install it on Raspberry Pi?

If you want to take pictures or record videos using Raspberry Pi board, you can install Raspberry Pi camera board. If you do not want to shell out money just for the camera board module, there is yet another way, which is to utilize a commonly found USB web camera. You may already have one for your PC.

In this tutorial, we show how to set up a USB web camera on Raspberry Pi board. We assume that you are using Raspbian operation system.

Before we start, it is better to check if your USB web camera is one of those which are known to be compatible with Raspberry Pi. If your USB webcam is not found in the compatibility list, don't be discouraged, as there is still a chance that your USB web camera may be detected by Raspberry Pi.

Check if a USB Webcam is Compatible with Raspberry Pi

To check whether your USB web camera is detected on Raspberry Pi or not, plug it into the USB port of your Raspberry Pi, and type lsusb command in the terminal.

$ lsusb

If the output of the command does not list your webcam, there is a possibility that this is because your Raspberry Pi doesn't supply enough power needed for your USB web camera. In this case, you can try using a separate power line for the USB web camera, such as USB power hub, and then repeat the lsusb command. If the USB webcam is still not recognized, we can only suggest you buy another USB web camera which is supported by Raspberry Pi.

In the above screenshot, the USB web camera is detected as 1e4e:0102, but it doesn't show the maker or the name of the web camera. When we try it with Fedora 20 in a laptop, it is successfully detected as 1e4e:0102 Cubeternet GL-UPC822 UVC WebCam.

Another way to check if your USB web camera is supported by Raspberry Pi is by checking the /dev directory. If there is /dev/video0, this implies that your USB webcam is recognized by Raspberry Pi.

Take a Picture with USB Webcam

After your USB webcam is successfully hooked up with Raspberry Pi, the next thing to do is to take some pictures to verify its functionality.

For this, you can install fswebcam, which is a small webcam application. You can install fswebcam directly from the Raspbian repository as follows.

$ sudo apt-get install fswebcam

Once fswebcam is installed, run the following command in a terminal to capture a picture from the USB webcam:

$ fswebcam --no-banner -r 640x480 image.jpg

This command will capture a picture with 640x480 resolution, and save it as image.jpg. It will not put any banner in the bottom part of the picture.

Here is the result from the fswebcam command with 640x480 resolution.

The next example picture is captured without defining the resolution. The picture color is blueish, and the default resolution is only 358x288.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean