Sunday, June 30, 2013

Build a Simple Internet Controlled Webcam Robot

This blog post will show you the basics of building your own internet controlled webcam robot. It's essentially a three wheeled piece of plywood board with a RaspBerry Pi computer and a tilt and pan webcamera. This will not be a thorough step-by-step description of the entire build, but it will give you a good understanding of the physical build, and a pretty detailed walkthrough of the software setup.

The prerequisites for this build are basic understanding of Linux, script and HTML programming and some soldering experience.


Hardware

All the hardware can be is easily acquired through web shops and your local hardware store. The total for my setup is around 200 USD, but if you're into electronics you probably have some of the parts lying around already.
  • Raspberry Pi Model A (~$30) - I got mine from Adafruit. In hindsight I might have chosen model B, to have the possibility of cabled internet connection. It would have saved me some trouble in the beginning.
  • SSD card (Minimum 8GB), cables, breadboard, and USB power supply (with USB micro connector) (~$50) - Use the stuff that you already have lying around and buy only the things you really need. The breadboard will only be used for testing.
  • Edimax EW-7811UN (~$11) - A simple USB wifi adapter. It worth buying this brand, since  Occidentalis (the Debian Linux based OS for Raspberry Pi) comes with the necessary drives installed.
  • Logitech C270 (~$23) - An affordable webcam from Logitech. You can of course use any webcam you already have, but newer ones will support MJPEG, which makes the live feed much faster.
  • 4 RC servos (~$30total) - I used the ones that came with my old RC radio, but you can get any kind. With my Hitec HS-325 servos I was able to easily modify two of them to spin 360 degrees in order to use them to drive to wheels of the robot. I suggest servos that provide 3-4 kg of torque for the wheels, smaller for the pan and tilt camera setup.
  • LiPo battery (~$30) - Any 2-4 cell LiPo battery will do. Choose it based on how much battery time you want your robot to have. I'm currently using a Polyquest 4 cell 4350 mAh battery, because I already had it from a previous project, but I would recommend something cheaper like a Zippy Flightmax 5000 mAh. I haven't checked the battery life while using it on the robot, but it should probably give approximately 12 hours of standby time. You will of course also need a LiPo battery charger.
  • UBEC  (~$5) - The Raspberry Pi and servos run on 5V DC, so we need this to to reduce the LiPo battery's 10+ voltage. Hobbyking has UBECs for less than 5 USD.
  • 2 hobby wheels (~$5) - Hobbyking sells these cheap wheels for use on RC planes. There's a trade off to be made between power and speed of your robot, depending on the diameter you choose for your wheels. You will also need a swivel wheel from some old furniture. 
  • 10-15mm (~$30) plywood, nuts, bolts, wires, micro switch, pipe hanger strap, double sided tape.
  • Fish-eye lens (~25) - Most webcameras have a narrow field of view. This makes navigating the robot like driving while looking through telescope. I've modified my webcam simply by putting a cheap fish-eye lens in front of it.

Software

  • Occidentalis - Debian based Linux distro derived from Raspbian Wheezy, created by Adafruit.
  • Apache 2 - Web server
  • PiBits Servoblaster - This is software for the Raspberry Pi, which provides an interface to drive multiple servos via the GPIO pins. You control the servo postions by sending commands to the driver saying what pulse width a particular servo output should use.
  • MJPG-streamer - MJPG-streamer takes JPGs from Linux-UVC compatible webcams, filesystem or other input plugins and streams them as M-JPEG via HTTP to webbrowsers, VLC and other software. 
  • HTML page - Shows the controls and streaming video (MJPEG), and sends controls to the Python CGI script.
  • Python CGI script - Sends values to Servoblaster, and executes OS commans to start/stop MJPG-streaming and shut down the Raspberry Pi.

Setting up the Raspberry Pi

This process is extremely well described on Adafruit.com and other places, so I will just point you the the relevant tutorials.
  1. Setup the Occidentalis OS on the SSD
  2. Setup WiFi on the Raspberry Pi - If you bought a Model A without cabled internet, like I did, you'll need to connect your Raspberry Pi to a USB keyboard and a screen using HDMI to set this up.
  3. Update/upgrade Linux, setup SSH and install Apache2 - Perform only the steps you see necessary.
  4. Optional: Test out controlling your servos from the Raspberry Pi - This process does not use the Servoblaster, and only supports one servo, but it's the fastest way to see some physical movement.
  5. Install servoblaster - Make sure you have updated/upgraded before trying this, or you will get errors!
  6. Install MJPG-streamer - This not actually an installation since, but we will set MJPG-streamer to be started at boot later.
  7. Give web-server user rights to run sudo commands without password (this is obviously a security risk, but if you're not using the Raspberry Pi for other sensitive stuff, it shouldn't be a problem): 
    1. sudo nano /etc/sudoers
    2. Add line: www-data ALL=(ALL) NOPASSWD: ALL
  8. Secure the web page - If you're going to expose the web page on the Internet I suggest you at least activate username/password authentication on your web server.

Writing the web page and Python CGI script


  1. Python script
  2. HTML page

Assembling the robot

I admit this part could use a more detailed description. I hope this get you an overview of the necessary steps. Use the photos at the top of the post to figure out the details.
  1. Open two of the servos and modify them to run 360 degrees
  2. Mount wheels on the two servos
  3. Cut out a piece of plywood 
  4. Mount swivel wheel to the plywood board
  5. Mount the wheel servos to the plywood board using double sided tape and pipe hanger strap
  6. Create a pan and tilt setup for the camera and mount it on the plywood board
  7. Split the signal calge (yellow) from the power cables of all the servos and plug them into the GPIO pins on the Rasberry Pi as indicated in the instructions from Servoblaster
  8. Create the power setup described in the next section

Video demonstration

Below is a short demonstration of the robot being controlled through the web interface and switching from a power outlet to battery power.

9 Comments:

February 23, 2014 Anonymous mohammed zuhair said...

Great project

September 12, 2014 Anonymous Fahmida said...

i was looking forward to make a internet control robot ( water vehicle) Can u help me out with some more detail about the making website and connecting that with the risberry pi ?

October 14, 2014 Blogger Unknown said...

i really love your project, it's a great project

i wanna make that robot, but i use camera from Android smartphone. but i need your help to make it run

can you send me your web server ?
i very need that to compare my project
and be my library

fristaasrori@gmail.com

February 15, 2015 Anonymous Andrea said...

thank you for sharing your project.
I am totally new with raspberry stuff.
an you tell me if I can use a raspberry 2 without modification of your software /project?
Thank you
Andrea

October 22, 2015 Blogger Unknown said...

"Hi Ramon, we are building your Raspberry Pi remote camera robot. We're having trouble with the power circuit. Did you ever detail it? Do you have a schematic? If not, can you identify the blue item on the bottom of the platform that seems to have 3 USB connectors? One is power in from the wall, one is power to the RP, and the third seems to go to the USB on the RP (the shielded cable) but I can't identify what it is. Where is the battery power connected inside that device? Thanks for your help."

James C. Wood
J.C. Wood Co.
225 Cattail Rd.
Templeton, CA 93465
(v)805-434-3633 (c)805-835-5303 (f)805-434-3697
jcwoodco@tcsn.net
No virus found in this message.

October 23, 2015 Blogger Ramón Arellano said...

Hi! Cool to hear that you're building your own robot. I don't have a schematic, but I can explain. Since I'm into RC planes I use a lot of RC equipment. For this robot iuse 11,1V lipo batteries. Those are connected to a simple ESC (RC speed controller) that includes a BEC (voltage conversion). It ensures that I have a constant 5V source, independent of battery level. In the picture the ESC is inside the black box in the middle (to reduce cable clutter). The 5V goes to the blue box, which is simply a USB hub.

January 12, 2016 Anonymous Aneesha said...

hello can you please help me with making of website and connecting it with arduino ?
mail me @ aneesha9424@gmail.com

January 19, 2016 Blogger Unknown said...

How did u make web page??

December 08, 2022 Anonymous Anonymous said...

The Aloha State considered one of the|is amongst the|is probably one of the} least-friendly states for gambling within the US. There have been some legalization makes an attempt in latest instances, though, and lawmakers thecasinosource.com have been working on HB 1815, which would convey at least of|no much less than} one sportsbook to the state. It is likely going}, nonetheless, that legalization of sports activities betting in Hawaii will take a number of} years, if it happens in any respect.

Post a Comment Home

Photos Flickr RSS feed

Project thumb

Personal photogallery

My personal photogallery generated using my own tool, Atacama. Pictures of events and travels from the last 10 years or so.

Project thumb

Flickr photos

All my photos at flickr.com. You can see the same pictures on my personal photogallery above.

Projects

Project thumb

Flash homepage

This used to be my web-site. Flash from bottom to top. Back then I thought it looked hot. Now it just looks silly.

Project thumb

Flash travels

This is the first page I created using Macromedia Flash. An interactive photogallery with maps and all.

Project thumb

Atacama

When I got tired of manually editing HTML every time I wanted to put out a new picture gallery, I finally wrote my own generator, in Java.

Project thumb

CasaCam

My dream as a kid was to control things in the real world using a computer. Now I use two small servo-motors to tilt and pan my web-cam.

Project thumb

Create-a-tree

Sitting in the garden in Chile during springtime inspired me think about how trees grow and sprout new leaves and branches.

Project thumb

Hobbyco

This is the web site for Kari's father's company. It's quite simple, but web statistics show that people are actually using it quite a lot.

Project thumb

Kari psykolog

Kari was sure she would spend months looking for a job as a psychologist in Norway. She decided she needed to promote herself using a home page.

Project thumb

NTNU thesis

This is my thesis from the Norwegian University of Science and Technology, where I took my Masters degree. I hope you can read Norwegian!