Webcams are a fun and useful tool. Being able to control where they’re looking remotely, though, takes their usefulness to a whole new level. Whether you’re watching your pets while you’re away or allowing friends to participate in an event from the other side of the world, a web-enabled remote servo camera puts the end user in control of the experience.
Put a Pi on the Web
The Raspberry Pi provides a perfect base platform for creating internet-connected devices. When researching how I was going to connect my device to the web, I ran into Make:’s very own Matt Richardson’s post describing how to use the Flask framework to easily create projects for the web on the Raspberry Pi. Flask allows you to take your existing Python apps (the preferred language for developing applications on the Raspberry Pi) and add in an HTML template to provide a web-page interface for the end user. In this project I provide an HTML template document that’s pretty bare-bones, so it’s easily understood by anyone who wants to look under the hood and also provides a good starting point if you want to customize it for yourself.
Stream Video from the Pi
The next tool needed was a way to send video from the Pi across the web. When using a less powerful system like the Pi, every little bit counts, and the real-time compression and streaming of video can be a huge drain on a system. After trying a couple of different options I opted to use MJPG-Streamer. The performance from MJPG-Streamer was hands-down the best of any service I tried on the Raspberry Pi.
Control the Servomotors
Finally I needed a way to control the servos for the pan/tilt mechanism. The standard library on the Pi for accessing the I/O pins is called GPIO. While GPIO makes it easy to do basic actions, its software-based PWM system is very inaccurate and temperamental for controlling servomotors. After running into problems and having a few friends review my code to ensure I wasn’t going mad, I decided to abandon GPIO in search of a better solution. The winner was an alternative to GPIO called RPIO. With RPIO, I had access to a semi-hardware driven PWM signal. This final piece brought it all together into a fully functional project and a great starting point for connecting your world to the web!
All the code for this project can be downloaded from Github and the 3D models from Thingiverse.
NOTE: eLinux has a list of Pi-compatible USB webcams. This project was built using the C260 webcam, which may no longer be available. The C525 reportedly “works fine without powered hub” but was un-tested with our design. The C270 reportedly “works fine with external power” in the form of a powered USB hub. The 3D design files are for the C260/270 but the premise for the design can be modified for the webcam of your choice.
Awesome job Matt! What printer are you using to make the case? I can imagine an octoprint mega server that would point the camera at one of the many printers you have in the room that happens to be printing.
Yeah, it would be fun to integrate with Octoprint too.
Great project, looks just like the one I made a year ago… Check out https://www.youtube.com/watch?v=rYKhGfZbj-0
can you make this wireless?
Thank you for the comment. Yes, this could be made wireless. It already uses wireless networking, so all that needs to be done is power the Raspberry Pi with a battery pack and then it would be wireless. I assume you would want a substantial battery pack to power the setup for a considerable amount of time…
thanks for the replie but how do i make the wifi wireless because atm it pluged in by ethernet, i need it to work over wifi but im not very good with raspberry pies, im just starting out
I don’t know how the MAKE version is setup, but on the one in my video all you have to do is:
1) boot to the GUI, plug in the USB wireless network adapter, Scan, Select the desired network, enter the network key into the PSK field, and write down what your new IP address is.
2) Edit the python script that references the IP address and put your new IP address in
3) Edit the HTML script that references the IP address and put your new IP address in
4) If you want to see the video stream from outside your network, then you will need to open a port on your router for your new IP address. You should be able to lookup your router type and find instructions on how to do this.
Good Luck!!!
hi thanks for your 3D design, when I try to print the 1st arm I get 3 piece, do I have to glue it ? or can you modify the design and make the 1st arm as one piece?
That is really strange. I will check the file to make sure there are no errors. What slicing engine are you using and what printer are you trying to print this on?
every thing print in good way, just 1st arm I get it 3 piece, the 2nd arm the internale arm was printed as one piece
Thanks for your support
I looked at the geometry of the stl file and for the arms; it’s a little malformed. It looks as though each original arm was created as three pieces and then exported as a whole. The issue is that this will result in overlapping geometry that the slicer has to stitch together. It doesn’t look like a boolean was used to join the elements or if it was, the boolean had a hard time. But on the up-side, I’ve found the arms print much better if you print them as 3 pieces per arm and then glue them together. This way the holes need no supports and as such are spot on (mine didn’t even need screws for the pitch servo it fit so well) and the inside of the holes are circular and smooth.
I’ll upload a new fixed version of the file shortly, for both all-together printing and printing in pieces. In the mean time, does the Up! have a radio button in the print settings to resolve holes and reversed normals? (my Afinia does – same printer – different software front end). You could try that.
this is my printer
Looks cool, but I wonder if anyone could sell the parts since I don’t own a 3D printer, or should I just buy a printer?
There is a link in the instructions to where you can purchase the parts you need if you don’t have a printer I have pasted it bellow too. Oh and yeah, you should also buy a printer!
You can also order the parts directly from me using my 3D Hubs account (if you live in the US). http://www.3dhubs.com/providence/hubs/matt
https://www.shapeways.com/model/1792280/raspberry-pi-case-with-servo-pan-tilt.html?li=shop-inventory&materialId=6
http://www.makexyz.com/ find a local printer.
I made this over the weekend, but I don’t have the software set up yet as I don’t want to flash my Pi with a new OS. I built this to use with my OctoPi box and I’d like to get the software, install it on my existing OS, and customize OctoPrint to have camera controls. I don’t know if I’m missing it somewhere in the article, but is there somewhere to download the code for whatever Raspbian software you included? A Git repo or something?
Thank you!
Any reason this project can’t use the RaspPi camera module?
who said it cannot? it’s just ‘better’ IMHO as it uses device you already might have at home and doesn’t involve spending hell load of money on a raspi camera
I’m having the problem with python that gives me NameError: global name ‘servo’ is not defined. Any ideas?
Great project Matt,
Remote access and servo control were like falling off a log, but getting the webcam to work with the web interface had me stalled. The chosen web cam works (have tested it with the “motion” library and with the mjpg-streamer port), and I can run two browser windows – one with the streamer port and one with the servo control, and that works. I just get the missing image icon above the servo direction buttons in the web interface. No other devices save the servos are plugged into the pi and it’s being fed by a 2 amp usb power source just for fun. Is there a browser plug-in I am missing for camera streamer in the web app? (latest firefox on OSX)
I have noticed, depending on the browser and site you view the Make project in, the terminal command that fires off the mjpg-streamer does not always have the spaces in the right places. So if someone were to copy and paste that string, and not be totally Linux savvy (or sleepy, like me – or is that “lazy”?), the wrong spaces, and sometimes a hyphen where a line wrap occurs on the web, can get put into the terminal by accident. And then of course a whole slew of errors appear.
I’ve edited this comment and added the following but left the comment intact so it might help others.
What I’ve discovered of course is that since I have to use the actual pi’s IP on my particular network to get through the ssh instead of ssh pi@picam, I also have to edit the HTML in the browser page by inspecting the missing streamer “image” element and change the html from http://pi@picam:8080 to the actual IP of the pi along with the port.
So for others who have to get to it the same way, you can just edit the HTML file (/home/pi/picam/templates/picam.html) and change the http://picam:8080 to http://theIPofYourPiHere:8080, and then it will just pop up when you hit the web page in a browser.
Cheers
So I took this to the next level and opened up two ports on my router so I could access the camera from anywhere. Why two ports? This LAN DNS issue cropped up again (see previous post). The first public port passes the incoming request to private port 80 for the servo control python script and a second public port allows the resulting picam.html page
to access the mjpg-streamer on private port 8080.
The picam.py worked great with one port open but the only way to make the streamer appear simultaneously was to hardcode the WAN IP of my router and the second public port into the picam.html file. Without the LAN DNS hiding the address of the WAN router address and public port, I feel like the front door of my network is hanging open for all to see. Apart from fixing this LAN DNS issue (which I am attempting) is there another way to get the html page to send back the port it needs for the streamer when the web app is out there in the world? Would the default picam:8080 addressing really work from a browser outside my LAN even if I didn’t have this LAN DNS issue?
Steve, did you come up with an answer to this question? I’m running into the same problem of requests from outside LAN only able to view (and use) the python buttons. No stream however.
I second Steve’s question. Anyone found a good solution?
for all of you out there, there IS security. you can enable it when you start the webcam with mjpg-streamer
Great article Matt! I just got it all up and running within 20 minutes and I am not a command line person!
I am using a USB webcam but I want to use the Raspberry Pi camera module AND I want to just output a 1 or a 0 in order to turn on and off the air conditioner in my garage at home. (the webcam will allow me to monitor my garage and also to see if the AC is on by the movement of a couple little plastic tassels I taped to the vents!)
So how hard is it to use the Pi camera module and to switch to just a binary output on the GPIO pins instead of PWM?
Thanks!
Just wondered if you had managed to get the pi camera module working with picam? If so how and where could I see the code? Thanks.
When I download the img. http://cdn.makezine.com/make/WeekendProjects/HomeSentrySecurityCamera/PiCam. it says its corrupt?
download or write?
OK….so I was trying to load this on a B+ which did not work. Now that I am using the B model, and it is loading, but it is asking me for picam login:
any ideas?
pi and raspberry
As for the log in prompt, user is pi and password is raspberry. When writing the img file to the SD using the imaging software in Windows 7, I found that using a 4GB card worked, the 16GB card errored out at 66% with write errors.
My issues I have not fixed, so HELP?? The initial running of picam halts at the end of pio23, motors never move. (Step 11). So, I went on, if I use port 8080 I get a message that jpg stream was successful with a small preview window, if I go to port 80, I get the controls and the servos move, but the image is not there, just a placeholder for it.
I have make my own, i have used a Logitech C170 (18€) and it’s works fine without powered hub.
I currently working on a boot up script using rc.locals
I have also set a little password using a function of mjpg-streamer “-c username:password” but i think it’s need to be improved.
Thank you Matt !
Hey @lucasbarrau:disqus did you flash the SD card with the specific image on the website or did you clone all the files from github?
I am also using the C170 webcam, but I got stocked when I want to watch the video, I guess it is because I got the code from github and I didn´t install it correctly.
Yes i flash the SD card, i have also use a Pi model B
Hi,
I’m doing this exact same project in my university(but a little different) and have a few questions.
I’m using CodeBlocks for the control from far computer-how do I access to the computer’s RAM to upload pictures, and where can I find a web protocol to tranfer from one computers RAM to another?
I know it’s a little bit heavy but do you know any sources that can help me start with that? I want to first transfer data between 2 computers and then connect the Rasbery pi.
thanks, Omri.
hi there i have a problem with one of the parts of the case. The part called pan it’s not manifold well in the program where i’m printing it says that it’s not manifold what can i do
yup it’s not booting on the B+…is there place I can get the files separate so I can add it to my current version of raspbian?
any reason why this wouldn’t work on a B+? maybe the OS is not compatible? Because it fails to load the image you uploaded, it just gives a black screen and nothing happens
I love this project by the way! I was thinking of making one myself when i found your post..great job..but still B+ compatibility would be nice..
how would you make this wireless because i am doing a school project and im looking to put this on a robots arm, any help?
add 2 battery packs (1 for raspi, 1for servos) and a usb wifi dongle and your set..dont buy the B+ because it wont work..get the older B model.. obviously you have to configure the dongle for the network you are under….
thanks for the support, has anyone got any good links to help me get started with raspian?
great article. I have managed to get this working with an of the shelf webcam and would really like to make it work with the raspberry pi camera module. Can anyone direct me to where I can see how to do that? Thanks.
hey want to ask i try it on raspberry b+ and the image can’t run on it. so i try to built it from sratch. anyone can help me i am stuck because i didn’t know where i can put picam.html. there is a error like this jinja2.exceptions.TemplateNotFound
TemplateNotFound: picam.html
Great article, thanks Matt. I’ve been toying with this for a few weeks now, and I had to compile and run things differently for the b+. I used servoblaster to control the servos instead and that worked great: I can easily control the servos from outside my LAN. However, my video feed only works on the local network. Outside of the LAN the browser page just shows the missing image icon.
I imagine it has something to do with the img src = ” ” line in the template html. But I’ve tried everything, including using the outside IP/?action=stream, and it won’t work. Any ideas out there?
Thanks again
will this stores/records the video into a local computer
will it store videos in local machine?
I was just wondering way the “Raspberry Eye, remote servo cam” no longer has steps to the build. It was here a few days ago, but now there is no longer any steps posted. Can this be fixed?
I think we are currently undergoing a wordpress theme upgrade and this is just an error. I will report it to the team and I have a feeling it will be back up and running soon.
Hi there, is this project at all possible using a B+?
Thats cool. Hey, want to see some quality 3d printed art? Check out: 3dprintedart.weebly.com
Hi All,
I just completed my Raspberry eye and it works great.
Here are the areas where I got stuck:
1) My Raspberry Pi is not able to supply power to the two servos via the USB cable. I had to provide external power to the two servos. If doing this, you need to have common ground like in the picture below. Also, the 1kohm resistor for each servo control wire helps a ton with signal noise.
2) See @Steve Bentley’s post if you are unable to connect to the PiCam via chrome–>In PiCam.html, change the line http://pi@picam:8080 to http://TheIPofYourPiHere:8080. Or if port forwarding, change it to http://The IPofYourRouter:8080.
Hey I followed all the instructions and I found the site of the picam and I can move the view around but I can’t actually see the picture. What is wrong?
My camera won’t show any image. It shows the missing image icon. I think the problem might be related to the pi not receiving or being able to send the image. Again I can still control the motors I just can’t see an image.
Very cool,
i made the project, only thing is mjpg wouldnt work with my raspicam, i already have mmal motion installed so i changed the html to point to the url of that stream, but im having problems with the servo, it confirmes that i click to move the cam, but nothing happends, im using the raspberry pi2 and plug the signal pins in number 8 pin outer and inner row, counting from SD card downwards, any suggestions to fix will be appreciated.
Nice project, had to modify a couple things to get it working for me.
1. Modified picam.py with app.run(threaded=True) so it wouldn’t freeze up after a while.
2. Used input_raspicam.so plugin with mjpg-streamer so that I could utilize my camera module instead of USB.
3. I didn’t see in the tutorial where it mentioned the ground wire for the connections, but for those of you using a separate 5v source for the servos you’ll need to add a ground from that source to the RPI headers to complete the circuit for the servo signal wires.
Im Getting the Error “UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device” Raspbery B+ is what I’m using with Logitech C110 webcam
is the Picam image is given is not in work.>
i download the Picam.img more than 3 time and try to install more than 15 time but every time get fail. after instillation and changing configuration file for hdmi mode…still no image on moniter…what the worng i m doing?
pls my mailid: 2011viveksonone@gmail.com
Can you use it outside??
picam.img is corrupt,any another link for this image picam ?
help please.
image file does not seem to work. Will this guide work with a Pi V3?
Could you use the RPi Camera module and Pimoroni’s Pan-Tilt hat instead with this project?
ConfigureACCEPT
Privacy Overview
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.