Internet Controlled movable Webcam
I finally got around to putting this back up on my new site. The following sections detailing this project were written when I actually built it and had it working in 2005 (before commercial swivel webcams became really cheap). The idea was to build a cheap, internet-controlled swivel base for a webcam without an analog to digital converter or any complicated logic circuitry. This writeup may be a bit confusing. Sorry, it was middle school ;)
Hardware
This project actually stemmed from an idea to build an internet-controlled robot. Figuring I should first familiarize myself with programming the Printer Port, I decided to start with something simple and cheap. Using a junked gearmotor and a cannibalized mini-tripod, I have built an internet-controlled swivel cam.
Components
- R2 = 330 ohms
- R1 = 1-4K
- Q1 can probably be any typical NPN transistor
- Put a 10K resistor between the X axis input and the wiper of the potentiometer -- I forgot to put that in the schematic.
- K1 is any suitable DPDT or DPST 5V relay.
You will need to build two of the parallel port portion of the schematic. For the second, reverse the connection to the motor so the motor will turn in the opposite direction. This way when one relay is on, the motor turns one direction, and when the other is on, the motor turns in the opposite direction. Though, you can build a maximum of 8 replications of the above circuit to be controlled by the 8 output pins of the Printer/Parallel Port. Solder the circuit's Parallel Port Inputs to the corresponding data out pins:
Fig: Female Parallel Port Connector
I built the motor system using a 24VDC gearmotor operating at 5V (to get a slower speed, and yes, the motor is overkill). I mounted the motor on a piece of wood with an L bracket and small pipe clamp. For feedback to know the direction of the webcam I used a 100K linear potentiometer rigged up to the motor's shaft using Lego Technic gears. I drilled out the axles to fit the shaft of the motor and rod of the potentiometer. Hot glue held it all together. Using a 1:2 gear ratio (where the potentiometer spins at 1/2 the speed of the motor shaft) gives a good, near-360 degree radius. Tip for gluing on metal: just hot gluing on a smooth metal surface does not stick very well, so rough up the metal with sandpaper a bit or use some other kind of glue.
Fig: The completed circuit. |
Fig: Mechanical Part |
To let the program know which direction the webcam is pointing I simply wired up the potentiometer and a 10k resistor in series connected to the joystick port using the Joystick 1 X axis. This method is really the easiest and dirtiest analog to digital converter available, but it suits the purpose well... and surprise! It's built right into QBASIC! All you have to do is use the Stick(n) command where n is the number of the axis. For the Joystick 1 X axis, the number is 0. (Remember under Windows to first let Windows know that you have a joystick connected. Go under Control Panel - Game Devices, or something like that, and choose 2-axis 2-button.)
Software
First off, I used Apache, since it is the most widely used HTTP server software on the net. To let it know how to handle .bat files, edit httpd.config and add .bat to every line with a CGI AddHandler. This way Apache treats the .bat files as cgi's and launches them on the server instead of prompting the client for a download. Zoomkat explains this in more detail.
Then I faced the issue of actually controlling the thing over the internet. Preferably this would be done through a browser and not by means of a special program. I ran across Zoomkat's website, where he has written out how to launch server-side .exe files using DOS batch files. I used his method, except instead of using the echoo app he used to control servos, I'm using a batch file to control my QBASIC printer port control program. Much of the information on the batch files can be found on Zoomkat's website. (download all server side files)
For posting images from the webcam on the internet I used a freeware Windows app called Webcam2000. To host multiple webcams simply run separate instances of the program operating with different ports, which can be accessed like this: http://yourdomainoripaddress:portnumber/image.jpg Then use javascript or another method to refresh the image after a given time, or use the built-in HTTP Refresh feature to do it automatically. Make sure you have either a static IP address or a dynamic address set up, such as DynDNS.org, and the port(s) forwarded to the machine's local IP address on your home router.
Below is a snippet of the JavaScript code I found on the web. Just put that in the section and add an tag in the body with the name 'theimage'. I then used Flash to make a control panel-type interface to let the user orient the camera. Flash isn't really nessesary, and you could just use HTML hyperlinks to do the same thing. (All this can be seen in action on the SwivelCam page)
<script type="text/javascript" language="JavaScript"> function reloadImage() { img = document.getElementById('theimage'); img.src = 'http://yourdomain:portnumber/image.jpg?' + Math.random(); } </script> <script type="text/javascript" language="javascript"> { setInterval('reloadImage()', 1000); // 1 second refresh, multiply seconds by 1000 } </script>
The above code works on both Internet Explorer AND Firefox.