The Raspberry Pi makes a great USB webcam for $100

There are many Raspberry Pi projects where I spend a few hours (or dozens of hours) building something with a Pi, and realize at the end that not only could I have purchased an off-the-shelf product to do the same thing for half the component cost, but it would work better too.

But this is not one of those projects:

Pi Webcam on Tripod - Pi Zero W and HQ Camera

The Raspberry Pi and its HQ camera make a surprisingly potent webcam, and if you want to cover the basics, and rival the image quality of all but the highest-end dedicated webcams, you can do it for under $100.

Still frame grab from recording on Dell XPS 13 using Raspberry Pi Webcam

Above is a single frame from a recording I did with the HQ Camera on my Raspberry Pi Zero W connected as a standard USB webcam using the Camera app on Windows 10 on my Dell laptop.

That particular Dell laptop is the infamous XPS model with a 'nose cam'—a camera placed in the most unfortunate location: under the screen, so it looks straight up your nostrils at a low angle:

Dell XPS 13 Nosecam built-in webcam

Dell fixed the camera position in newer XPS laptops, but most laptops still have a pretty poor excuse for a camera in their thin display bezel—there's just not enough room in there for a good sensor and lens.

Video for the Pi Webcam

I go beyond the content of this post with demos, an assembly guide, and more, in my video Raspberry Pi Zero is a PRO HQ webcam for less than $100!. Go check out the video for a ton more detail than I could cover here.

A real USB webcam

Using the power of the Pi's OTG port, you can build a true USB webcam—not some hacked-together IP camera that requires extra software to work, requires a flaky ffmpeg stream over the network, or only works with a specific app. The Pi Zero's USB port allows power to be delivered to the Pi, and data communications at the same time—perfect for powering a simple camera:

Raspberry Pi Zero with USB OTG cable plugged in for webcam use

There are now many posts and Gists detailing the process of enabling this OTG webcam, most notably David Hunt's blog post: Raspberry Pi Zero with Pi Camera as USB Webcam.

David Hunt blog post talking about webcam gadget scripts and serial devices

But most of these resources dive straight into configuring dtparams, modifying boot configs, compiling C code using make, and enabling serial interfaces... and all I wanted was a quick way to turn my Pi into a reliable little USB webcam!

So I spent a few hours working everything into an open source project that uses Ansible to deploy the software to the Pi with simple, understandable automation. It can be run either on the Pi directly or from another computer: Raspberry Pi Webcam on GitHub.

This project installs a lightly-modified fork of one of the popular uvc-gadget repos with the software that makes everything work (you can configure what fork it uses)—but my intention is only to make the installation quick and easy so more people can use the Pi as a webcam, even if they aren't programmers.

During the pandemic this year, it's frequently hard to get a webcam, but I've noticed Pi Zeros and HQ Camera modules have been well-stocked as the year has worn on. If you can't buy it, build it!

I'm hoping that more people in the community can work to make the underlying uvc-gadget application (which has a ton of disparate forks right now) easier to configure and more stable (right now it only works on the Pi Zero unless you run an older release of Raspberry Pi OS!.

Anyways, the Raspberry Pi Webcam README has all the details for setup of the webcam, including every part that I used to assemble my own webcam.

The process takes about 20-30 minutes, including assembly:

  1. Flash Raspberry Pi OS to a microSD card.
  2. Boot that card in the Pi, complete the setup wizard, and run the pi-webcam playbook on it.
  3. Shut down the Pi.
  4. Assemble the camera module to the Pi.
  5. Plug the Pi Zero's USB port (not PWR IN) into your computer's USB port.

After 30 seconds or so, any standard video software should identify and be able to use the webcam.

Raspberry Pi HQ Camera on Pi Zero with Pi 400 used as a webcam

And in case you were wondering: Yes, the Pi Webcam works great with a Pi 400—I used it to record a few video clips and also to chat via Google Meet online:

Jeff chats with Joel on Google Meet on the Pi 400 using the Pi Webcam

Question: What about showmewebcam?

I like that project, and am following its progress as well. Though I don't like the idea of downloading a random Pi OS image and dropping it on a general computer like the Pi, especially if said computer has a camera attached to it. I'm not implying anything malicious, I just like having more fine-grained control and understanding over what I'm installing.

That said, the showmewebcam project does have some nice features like faster boot, and setting the ACT LED to turn on when the camera is in use, and off otherwise.

Not all is perfect

There are a few tradeoffs, of course, and I'd be remiss to not mention them here:

  1. No built-in microphone: You will need to use a separate mic or your computer's built-in microphone.
  2. No autofocus: For me, it's not an issue as I use it in fixed positions with subjects (like myself, or a project on a workbench from above) that aren't moving out of the focal plane.
  3. Dropped frames and latency (especially on older Pis at higher resolutions): I set the default to 720p which works great for most cases, but if you want to push to 1080p you can run into dropped frames or even latency, which requires adding audio delay so it is in sync with the video (e.g. via Audio Hijack or OBS).

For many, the tradeoffs are worth it. For people who need a more portable solution, it might not be as nice to always have to mount the Pi and set its focus. Plus it is a slight bit larger than your typical cheap webcam.

Adaptability adds to the appeal

The other nice thing about the Pi and the HQ Camera module is that it is fully programmable and of decent quality, and so in addition to its life as a webcam, I've been using the combo for timelapses, background footage, and even wildlife video and astrophotography (more on that soon!).

Some people have questioned the utility of the HQ camera module, but I embrace it—having a couple of these cameras, along with adapters for my Nikon F and Sony E mount lenses, along with a Telescope 1.25" C-mount adapter means I have a software-controllable camera that I can easily use with any of my lenses or telescopes to explore some new photography and video ideas.

Many of my Pi projects end up costing more than over off-the-shelf products with a worse end-user experience—but I learn a lot in the process, and the projects inspire more personal creativity, and that's worth a lot more to me.

But in this case, I'm happy to report my Pi Webcam actually is a better value, in some regards, than boring old webcams—especially since you can usually find the Pi in stock!

Comments

I can recommend this as a simpler alternative:

https://github.com/showmewebcam/showmewebcam

That's a dedicated buildroot based image to turn your pi into into a webcam, without the issues of shutdown - just disconnect without any risk of corruption.

How's the low light performance of the high quality camera? That's the only concern that's stopped me biting so far, but the pi Zero and standard camera in the official case makes for a neat webcam size package, but it needs good lighting.

Heh, see the "What about showmewebcam?" inline note in the article—I do like the idea, and that project seems to have a lot of momentum as well, so I'm following it with interest. I still don't like the idea of flashing someone else's built OS on my computer especially when my computer has an Internet connection and a camera attached. But it's a matter of trust, and if I can just build my own version from my own toolchain, I might be willing to run with that project more.

Given that the filesystem is laid bare for all to see after writing the image to the sd card, and that the image has no network stack, I'm curious what you think the danger is here. This project is on github too -- seems like a great way to get sued if it does something nefarious. Don't forget that Raspian OS is also "someone else's built OS" -- I think you did a video recently about the claim it was "calling home" to Microsoft? Maybe there's a new video here for ya to make --- DANGERS of random PI images!

I tried your project first, but later tried showmewebcam. It was far far easier to set up (copy image to sd card and boot -- done), much faster boot time -- (like 10 seconds at most maybe less?), and you don't have to worry about file system corruption because root boots as read-only. Shell via screen is a treat too! However, I can understand you wanted to back your baby, especially after all the time you must have put into it!

Comes with some nice utilities to tweak the camera settings in real-time too, but maybe yours does as well?

The only problem I have is with the camera module itself: It doesn't have a white balance temperature setting -- just preset choices that don't always work well. Oddly there's a "manual" choice, but I couldn't figure out how to make adjustments to it.

One bonus is that this camera doesn't have a UV filter like with all? webcams, so you can use it to test/see remote control leds, or use it with something like Shootoff with a uv laser ammo. Now I can test my roomba's sensor lights to see if any have burnt out! :)

"The only problem I have is with the camera module itself: It doesn't have a white balance temperature setting -- just preset choices that don't always work well. Oddly there's a "manual" choice, but I couldn't figure out how to make adjustments to it."

The manual setting for white balance is weird! You can adjust the green and red channels to find the balance, it's not a good solution (yet) but maybe you want to pop a ticket on GitHub to get the kelvin scale manual whitebalance?

Just buy a better web cam without the hassle. What a stupid projecg.

Your intelligence is summed up as an emoji. Even the text-emoticon have done much better.

and a better webcam would cost? this project is about getting quality for a reasonable price. and the pi is a multi purpose device, and the better webcam, hmmm..; pretty ignorant commentary

Time to balance out the stans here. To use this webcam: Step 1) Plug in usb into your tower pc w/ vodka cooling that you all have. Step 2) wait 10+ seconds for the pi to boot. Step 3) wait a couple seconds for the cam to prepare. Step 4) Done, ready to win any slowruns. lel.

This .... is pretty much exactly what I was looking at doing with my plethora of spare pis. I wonder how difficult it'd be to work with a raspberry pi 4 instead of a zero - I've already put together the Adafruit 3d printed case from thingiverse.

Only $100 for a webcam is a deal? You know that a normal USB webcam can be had for $20 right? I’m all for the Raspberry Pi but “plug the Pi camera in and flash a SD card” is a pretty pointless application when there’s cheaper alternatives available.

The whole point is that there are many ~$100 (and much more expensive) webcams, and the $20 webcams are a whole level of quality worse than the $100 tier. The Pi camera in this post competes well with the same-priced cameras, with the added benefit that it's fun to make, is more of a conversation piece, and can be used for many other purposes as well :)

The point isn't that this is the cheapest webcam in the world. There are zillions that are cheaper. It's that it is a very good webcam for the same price as a number of other very good webcams—most of which are hard to actually find for $100 right now.

Not to mention the ability to swap lenses as needed. My Logitech C920 is fine for zoom calls, but there are times that I'd like to swap over to a fish eye to show off a 3d print in progress.

Hi Jeff,

we fixed all the mentioned problems (high cpu load/temperature, limit to 720p) and much more over at showmewebcam. Additionally it is quite easy to build yourself, if you don't trust a random image file :) Finally, you can still log in over either SSH or via the USB serial console. Feel free to join us or use our fixes.

It sounds like I'll have to at minimum test it out on one of my Pis soon :)

I like the fact that showmewebcam is actually getting active development—so many of these other projects end up just getting abandoned after the original author gets it working once!

Great project. The thing I most like about it is how it gives this collection of hardware real usefulness right away along with a "restore point" I could use if I end up hacking on it to do more once I get it working. Thanks for putting this together.

One suggestion: Could you put the links to the parts in this article?

I actively avoid clicking truncated URLs in YouTube descriptions both because of advertising redirects and because it's a crummy experience. On iOS it tries to launch into YouTube.app's built-in web view and on desktop I get an interstitial "are you sure you want to leave YouTube?" web page.

So by going your route, do you get manual control (Well programmatic control at least) over things like Shutter Speed, ISO, etc.?

That would be a huge benefit to this over webcams.

Love this! I already had a Pi Zero lying around and I've been looking for any excuse to buy the HQ camera. Works perfectly on my Macs and Pi 400. Thanks and keep updating on any other HQ camera uses you find...

I just set this up and it's working great so far! is there a way to set the white balance for this though? the White balance is a bit off and I'd like to be able to adjust it in the Pi itself since I'm using it for google meet and there's no way to change it there.

I'm still pretty new to Linux and Raspberry Pi, so I might need a bit of hand holding (I've dabbled in Linux over the years and this is my first Pi).

Any help would be appreciated.

Thanks!

If you can connect to the Pi, it seems like you could run commands like the following on the Pi:

/usr/bin/v4l2-ctl -c auto_exposure=0
/usr/bin/v4l2-ctl -c auto_exposure_bias=8
/usr/bin/v4l2-ctl -c contrast=20
/usr/bin/v4l2-ctl -c video_bitrate=25000000

But follow this issue for more progress making picture control customization easier: Allow configuration of resolution, framerate, white balance, brightness.

Would this project work on the CM4 using the regular I/O board?

How exactly would one connect a Raspberry Pi 3 A+? I know you have to set the overlay in /boot/config.txt, but is the power port OTG enabled, or do I have to use the USB A port? If I have to use a custom cable on the A port, what's the correct pinout?

Or, could I use something like this with a standard USB C cable: https://www.adafruit.com/product/4053

Hello Jeff,

You wrote that it works in Teams.
I setup the camera and yes, it works fine with Windows 10, in the Teams client I even can see my own preview, but none of the other meeting participants can see my video.

Did you use the Teams client or the web browser?

Thanks,
Balazs

Built it with a Pi ZeroW and an old Pi camera module I had in the drawer. Worked perfectly.

My only question is can you advise if it's possible to tweak the settings for the camera? I have it in a Pi Zero case and would like to rotate the picture 90 degrees.

I looked at the parameters for uvc-gadget and v4l2-ctl but don't see how to rotate the image. It seems I can change the contrast and perhaps the brightness.

Had the same question - the feed from the v2 https://www.raspberrypi.org/products/camera-module-v2/ when plugged into a computer (Macbook in my case) has the image rotated clockwise, as if in a "portrait" mode. Assuming this is the difference between the HQ module and the v2 module. Still completely functional, but I wonder if there's an easy fix? Or way to rotate for user preference? Perhaps a quick edit to a config file? Thanks again, really enjoying your channel and getting into the pi.

Yes, that worked. For some reason after I edited the file and ran "sudo reboot" the PiZero didn't respond when it came up, so I unplugged it and plugged it back in. From there everything worked as before but now with 90 degree rotation.

I had searched for a rotate command with "v4l2-ctl --help-all | grep -i rotate" and came up empty. So I'm glad the link you provided gave a solution. Now if you have a command to get rid of double-chins . . .

Jeff-- Just want to say how much I've enjoyed a number of your videos (I know, I should support you on Patreon, and I will). Keep up the great work.

My wife gave me an Arlo video doorbell for Christmas and it installed and ran very easily. But I imagine you have realized a Pi camera could do the same (if it has enough compute power). Have you considered such a project?

--Hal

There are a few projects like https://piwebcam.github.io which have more configurability for an IP-camera setup. For cloud-based video notification services, something like Ring or Arlo has a leg up for the battery integration and features that make it really quick to set up and easy to keep updated.

But you could build a system based on Pi cameras without too much struggle!

I have a Pi 2B & a Pi 4B (8GB). If I were to use either one of those for this project, would they fix the dropped frames & latency when set to 1080p? I was thinking of getting a usb male to male adapter to plug into my Pi and my Windows, but I want to know if it's only compatible with the data micro-usb port on the Pi Zero. Thanks!

Hi Jeff,

Thanks for pulling all this together and sharing with us.

Do you know, or do you have any ideas, how this could be used to do background replacement in the PI, rather than using the Teams, or Zoom feature? Not all of the Video Chat tools I use are able to do this at all, or well in some cases. It would be great if this processing could be added to the PI, and work well without a green screen.

Thanks!

Nice work!
Had some problems adjusting the focus of the camera. Found out that the camera i bought , the 6mm 3MP needed the back focus attachment ring not tightly screwed in but about half way to get a picture at all!

Thanks for this Jeff - a good idea and looks like good work to simplify things for the rest of us. I'm going to build this and then come back with 1000 questions.

Hi Jeff.
Thanks for your excellent explanations. I used it on my Rpi zero w. it works fine for the first time when I plug the Pi into my laptop and pi boots up. I use a separate power source besides my Rpi. when I unplug and re-plug the connection, the laptop does not recognize the uvc camera anymore until I restart the Pi. do u have the same problem?

can u add autofocus using something like a ir proximity sensor....

Hey Jeff,

I'm having trouble changing the resolution to 1080P on a raspberry pi 4. I followed your original guide and got it working with 720P default.

To switch to 1080P, my understanding is that you go through all the steps of the original guide, including running the Ansible Playbook, but DONT SHUT DOWN.

I was able to edit both the piwebcam and multi-gadget,sh scripts, then shut down.

The camera is recognised by windows but there is no image in the camera app as before with 720P.

Can you tell me what I'm doing wrong?

Thanks!

I'm trying to use this to build a microscope, but not being a programmer, I'm running into a problem: after installation of git, Ansible and everything else, following the instructions to the letter, when I try to run ansible-playbook main.yml, it comes up with an error - 'couldn't resolve module/action 'make'. This often indicates a misspelling, missing collection or incorrect module path. The error appears to be in /home/pi/pi-webcam/tasks/uvc-gadget.yml' line 9, column 3...' but looking at that particular file, line 9 column 3, assuming counting from 1, just says 'Build uvc-gadget.' I tried modifying that particular line in the file to add '.yml', but it's not working. Does anyone have any suggestions?

Hey Jeff, Great work mate.
Could you share some info on how to set the awb-mode. The automatic white balance is changing the video colors all the time for me.

Thanks

Thanks for doing this Jeff. I've been binging on your Youtubes recently, and this little RPi Webcam project I put together the other day once some bits were delivered pushed me over the line to sponsoring you on Github.
I foudn the Adafruit tutorial about setting up a Pi into read-only mode, with a nice little script to automate it, nailed it for me - now I can pull the USB cable without worrying that the uSD card gets corrupted.
https://learn.adafruit.com/read-only-raspberry-pi

Hi Jeff,

Thanks for all this. I followed all the steps and I am stuck.
I have the Pi Zero W connected via USB to a Linux mint via USB as per your guide.

I can get into the Pi via VNC and I can use the camera that way to take pictures but google hangouts doesn't recognise the camera as an option.... so the camera is there and running but I can't see it as a USB webcam, or at least not with hangouts.

What could be the issue? What can I try? How does the playbook work? Can I run it via VNC? Do I run it, shut it down and try every time or after running it once it stays "alive" regardless of shutting down the pi?

Cheers