USB Webcam access in your Raspberry Pi

USB Webcam access in your Raspberry Pi

The Raspberry Pi recognizes most USB webcam and you can use them right away! You just need to add a few applications to run in the background and then it will start right away!

Do you plan to use them as a surveillance camera? Although no the best option for security but it can become certainly handy in many cases. Click here to know to have remote access to the Rasbperry Pi. Since many cameras are located in remote locations, this tool is highly recommended.

Installation

Before starting a new setup, be sure to make an update to the repositories in your Raspberry Pi.

sudo apt-get update

Connect the USB webcam and type this code in the terminal to make sure the Raspberry Pi has recognized it.

lsusb
Webcam recognized by the 'lsusb' command.
Webcam recognized by the ‘lsusb' command.

As you can see in the first item, device 004, it was recognized and it is ready to use.

The software required for this tutorial is ‘Motion‘ (check their website!). Type the following code to install it. The -y in the end is just an auto-confirmation for the installation.

sudo apt-get install motion -y

Configuration

Type the following code to access the configuration of the software.

sudo nano /etc/motion/motion.conf
motion Raspberry Pi USB webcam
Motion Configuration

Search for the following lines and change the default value to the value specified below (just erase and write with the new values):

daemon on
width 640
height 480
framerate 10
stream_localhost off
webcontrol_localhost off

There is an explanation for every feature above each one. After you are done, press ‘Ctrl + X', ‘S' (or ‘Y', depending on the settings language) and ‘Enter' to exit, save and confirm respectively.

Under the “Live Stream Server” there is the ‘stream_port' which is the port that web are going to be using for this demostration. By default, the port is 8081; unless you need to change for any good reason, leave it as default.

Now type in the terminal the following command and change the ‘no‘ to ‘yes‘ in the “start_motion_daemon” option. Save the file and exit.

sudo nano /etc/default/motion

Testing the USB Webcam

Let's start that daemon! Type the following command in the Terminal:

sudo service motion start

You could also try these commands as well

sudo service motion restart
sudo service motion stop

Now, let see what the USB Webcam sees! Open a new browser window and enter the address of your Raspberry Pi and the port after a colon ‘:‘.

RPi-IP-Address:8081

In my case, I wrote this:

http://192.168.1.32:8080/

Here is the result:

  • USB Webcam

That's it! It works and I receive and image rom the webcam through this website. Open another webpage with the port 8080 instead to take a look to the webcontrol feature.

Although you can't see much during the night but this depends on the USB Webcam entirely. If you need to have night vision however, make sure you buy one USB Webcam with this feature.

Unless you want give strangers access to your camera, it is a good idea to

Type the following command in the Terminal.

sudo nano /etc/motion/motion.conf

Scroll down until “stream_auth_method” and select an option (just erase 0 and replace by a number of the list); option “basic authentication” may suffice for many applications.

Authentication options in Motion in Raspberry Pi.
Authentication options in Motion in Raspberry Pi.

On the next option, select the username and password and don't forget to save the file!

You have reached this far!

Thank you for reading the blog post. Your comments and suggestions are welcomed. At the bottom of this page, leave a message or just say hi! The whole team of techZorro will appreciate it. Don't forget to share it on social media as well.

techZorro’s Index of Content

Click on the following link to browse likewise content in the blog in techZorro. This index will help you see what you are looking for in a bird’s eye view.

techZorro's Newsletter!

If you enjoyed this blog post, please subscribe to techZorro’s newsletter so you don’t miss any future blog posts!

Leave a Reply

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