Setup a USB Webcam for Streaming on Raspberry Pi

Setting up a USB webcam on a Raspberry Pi for live streaming is a straightforward process that involves connecting the hardware, installing streaming software, and configuring the video feed. This guide walks you through verifying your webcam connection, installing the lightweight Motion software, and configuring the network settings to broadcast a live video stream over your local network.

Hardware Connections and Verification

Before configuring any software, ensure your Raspberry Pi is powered down. Plug your USB webcam into one of the USB ports on the Raspberry Pi—preferably a USB 3.0 port (blue) if you are using a Raspberry Pi 4 or 5, as this provides better data transfer speeds. Power on your Raspberry Pi, open the terminal, and run the following command to verify that the system recognizes your camera:

lsusb

Look through the generated list for the name or manufacturer of your webcam. If it appears in the list, the Linux kernel has successfully detected the device. To further confirm that the video device node has been created, run:

ls /dev/video*

You should see /dev/video0 or a similar entry, which indicates the camera is ready to capture video.

Installing the Streaming Software

While there are multiple tools available for streaming video, Motion is a highly popular, lightweight choice that is easy to configure for a basic network stream. First, update your package lists to ensure you install the latest version:

sudo apt update sudo apt install motion -y

Once the installation is complete, the software is ready to be configured. By default, the Motion service runs in the background but requires a few tweaks to allow streaming outside of the local Raspberry Pi interface.

Configuring the Video Stream

To edit the configuration file for the Motion software, open it in the Nano text editor with administrative privileges:

sudo nano /etc/motion/motion.conf

Scroll through the configuration file and locate the following parameters, changing their values to match these settings:

Press Ctrl + O to save the changes, then Enter, and press Ctrl + X to exit the editor. Next, enable the Motion daemon by editing the environment file:

sudo nano /etc/default/motion

Change the line start_motion_daemon=no to start_motion_daemon=yes, then save and exit.

Starting and Viewing the Stream

Restart the Motion service to apply all your new configurations:

sudo systemctl restart motion

Your Raspberry Pi is now actively streaming video over your local network. To view the stream from another device (like a laptop or smartphone connected to the same Wi-Fi network), you need to know your Raspberry Pi’s local IP address. Find it by typing hostname -I in the Raspberry Pi terminal.

Open a web browser on your secondary device and enter the IP address followed by the default Motion streaming port, 8081, in the URL bar:

http://<YOUR_RASPBERRY_PI_IP>:8081

The browser page will load a live, continuous video feed directly from your USB webcam.