|
To control a webcam with two servo motors (pan and tilt). Easy and simple to build, only need some basic knowledge about electronics and programming. This circuit is based on a PIC16F84 Controller. The total cost of the project is about 40 Euro (40$) including two servo motors and one PIC16F84. All the software/code can be downloaded as free or shareware. ;)
Robotic WebcamHow to buildFirst of all you have to build a programmer then connect the Programmer to your Comm port and burn the code to the pic. You can write your code yourself but for this project but you can also download the code. If you want more information about pic programming, There is a lot of information on the web. For burning the PIC you need some software. The software that i used was from http://www.ic-prog.com/. After succesfully programming the pic it's time to build the servo controller. Remove the PIC16F84 from the programmer and insert it into the servo controller. Connect the circuit to the serial port and if everthing went well it should be working. you can the test the servos with the free servo controller from http://www.rentron.com/servo.htm
For controlling the servo you can use different kinds of languages suchs as Qbasic, Pascal, Delphi or C++ what i used was vbscript. With vbscript it's easy to make a website for controlling the webcam. The PIC Programmerhttp://www.circuitsonline.net/circuits/view.php?id=91 Part-List - 10k Ohm
- 15k Ohm
- 100uF Capacitor
- BC547B transistor
- 5,1V zenerdiode
- 18 pin's IC Holder
- DB9 connector (RS232)
The Servo ControllerPart-List - PIC16F84-04/p
- 4.7 KO
- 22 KO
- 4Mhz Ceramic Resonator
- 0.01uF
The SoftwareThe software that i used can be downloaded from http://www.rentron.com/servo.htm Here you can find the free code for the PIC16F84 and the "free servo controller software" to test the servos VBscript Example For this Example you have to have Visual Basic installed to register the mscommlib.mscomm component Copy and past the code to a text file and call it Control.servo.vbs. Open command line and type for example: control.servo 1 90. This is script can be very usefull if you want to make an ASP page. '--------------- Controlling a webcam with two servos ------------ If Wscript.Arguments.Count <> 2 Then Call Usage end If
Dim com_port
Sub Usage Wscript.Echo "------- Usage: control.servo [Servo Nr (1-2)] [Position (90-180)]" Wscript.Quit End Sub
Sub ControlServo (intservo,intPosition) wscript.echo "position servo nr " & intservo & " in position:" & intPosition Set com_port = CreateObject("mscommlib.mscomm.1") com_port.commport = 1 com_port.settings = "2400,N,8,1" com_port.portopen = True com_port.Output = chr(intservo) & chr(intPosition) com_port.PortOpen = False End Sub '------------------------------------ Main ---------------- intServo = WScript.Arguments(0) Intposition = wscript.Arguments(1)
If IntServo < 1 or IntServo > 2 Then wscript.echo "Incorrect Servo Number (1-2)" ElseIf IntPosition < 90 or IntPosition > 180 Then wscript.echo "Incorrect Position (90-180)" Else Call ControlServo(IntServo,IntPosition) End If |
Python Example Recently i switched to Ubuntu. Now i can remote control my camera via ssh. To make this servos work from Linux you can use Python. Here is an example. import sys import time import serial def ControlServo(x,y): print "" print "Move servos to new positions." s = serial.Serial( port=1, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=0, rtscts=0, baudrate=2400 ) print "Move X axis to " + x s.write(chr(1) + chr(int(x))) time.sleep(2) print "Move Y axis to " + y s.write(chr(2) + chr(int(y))) time.sleep(2) return if len(sys.argv) != 3: print "\nUsage: Servo.Control.py <X> <Y>" print "\nMove servos to new position" else: x = sys.argv[1] y = sys.argv[2] if int(x) < 60 or int(x) > 230: print "Invalid X value (60-230)" sys.exit() elif int(y) < 90 or int(y) > 180: print "Invalid Y Value (90-180)" sys.exit() else: ControlServo(x,y) |
I extended my script with a bash script to grab an image from my webcam and upload it to an website. print "Grabbing image" os.system("camgrab") #use camgrab to grab an image. print "Uploading image" os.system("./UploadImage.sh") #script to upload file by ftp to a website. print "Done.." |
In Action ..See the webcam in action (Youtube) Related Links |