Unit 03 Section 02 Lesson 08

Pan and Tilt Camera Mount

Assigned activities

In this activity you will develop a pan and tilt camera mount and a visual basic interface to control and view images from the camera

Activity 1
Part 1

Required Resources

Pan and Tilt Assembly Fabrication

NOTE: Remove the screw from the white control wheel on the servo motor. Place the screw in the small hardware container and DO NOT LOSE - this is the only screw that will fit the servo motor mount without damaging it.

Pull the wheel off the motor

Check your kits for the parts. The hardware (nuts & bolts) are in the small plastic containers.

Locate a small bolt (hex head) with 2 plastic washers and a plastic cap nut (see below)

Push the bolt through the hole in the servo motor bracket (the one mounted on the rotary base.

Next position a servo motor in the bracket. The shaft of the motor must be in-line with the screw you just placed.

Fasten the motor with at least 2 push pins.

Attach the white control wheel to the servo motor bracket as shown in the next sequence. Use 2 small self tapping screws (or if the holes in the wheel have been drilled out use 2 small bolts and nuts). Make sure the wheel is centered on the bracket hole.



Next mount the C bracket on the servo motor shaft and on the screw you previously placed in the bracket. The washers and cap nut must be placed exactly as shown in the next illustration. You may have to bend the C bracket out slightly to get it to fit over the servo shaft.

Finally, turn the C bracket. If it does not turn equal angles from the vertical position, slip the wheel off the motor shaft, turn the C bracket and reattach. When the C bracket is centered, replace the servo shaft screw to secure the control wheel.

Don't mount the camera yet. We will do that later.

Circuit Configuration

Connect the bottom (pan) motor to connector 0 (first) of the Phidget Advanced servo controller. Connect the upper (tilt) motor to connector 1 (second). Make sure the yellow or white wire on the servo line up with the W on the connector. Attach a 12 volt power supply to the controller. Finally, connect the USB cable to the computer.

Create the Graphical User Interface

Note: Save your project at frequent intervals!

Run Visual Basic 6.  Select a Standard Exe.

  • Draw a Frame on the form.
  • Draw the following controls on the frame. A suggested layout follows.
    • A vertical scroll bar
    • A horizontal scroll bar
    • 2 text boxes, place text1 by the horizontal scroll bar and text2 by the vertical

Change the properties for the following:

  • Frame1
    • Caption - Pan & Tilt Control
    • Font - Arial, 14pt, bold
    • Backcolor - something appropriate
  • Text1 & Text 2 box:
    • Text - Delete the default text (Text1)
    • Font - Arial, Bold, 14
  • Hscroll1
    • Min - 0
    • Max - 180
    • Value - 90
  • Vscroll1
    • Min - 0
    • Max - 180
    • Value - 90

Code the Interface

  • You will be using the PhidgetAdvancedServo therefore the Phidget library must be referenced. Open the Project menu and select References.

    Scroll down and check Phidget Library 2.1. Click OK.
  • Open the code window. Start by selecting General...Declarations in the small windows. Enter the following code:

 Dim WithEvents Servo As PhidgetAdvancedServo

  • Code the Form_Load procedure:

Set Servo = New PhidgetAdvancedServo
Call Servo.Open

  • Code the HScroll1_Change procedure with the following:

Servo.Position(0) = Hscroll1.Value
Text1 = Hscroll1.Value

  • Code the HScroll1_Scroll procedure with the same code:

    Servo.Position(0) = Hscroll1.Value
    Text1 = Hscroll1.Value

  • Code the VScroll1_Change procedure with the following:

Servo.Position(1) = Vscroll1.Value
Text2 = Vscroll1.Value

  • Code the VScroll1_Scroll procedure with the same code:

    Servo.Position(1) = Vscroll1.Value
    Text2 = Vscroll1.Value

  • Finally select servo....OnAttach from the small windows at the top of the code form and code the following:

For i = 0 To servo.MotorCount - 1
   servo.ServoType(i) = PHIDGETCOM_SERVO_HITEC_HS322HD
   servo.Engaged(i) = True
   servo.VelocityLimit(i) = 40
   servo.Position(i) = 90

Test the System

Save the project. Run the program and make sure the camera mount moves to the "home" position when the program starts (middle position for both motors). Check to see that the vertical and horizontal scroll bars actually control the motors.

Getting the Camera to Work

You are going to use a third party custom control to view the camera output on the Visual Basic form. The control is called ezVidCap. Check to see if it is installed on your computer by following the instructions below. If it is not listed in the components window, you will need to download and install. This will have to be done by someone with administrator rights.

If ezVidCap is not installed use the next link.

Download ezVidCap (zip file)

If the control is installed do the following:

  • Open the Project menu and select Components.
  • Scroll down to and select ezVidCap. Note: you must click the box so that the check mark appears. Click OK

  • Look at the bottom of the tool bar. A new control should be added (circled in red). Select and draw on the frame.

  • Position the control as shown next.

Finally, attach the web cam to the top of the C bracket using the camera mount which should be already attached.

Save and run the program again. If you don't see an image in the ezVidCap window, you may not have drivers for your particular camera installed.

Joystick Control - Part 1

A joystick can be used to make control of the camera easier. It is assumed that the global majic custom control is installed on your computer. Start by adding the joystick control to the toolbar.

  • Open the Project menu and select Components.
  • Scroll down to and select GMS Joystick check the box). Click OK
  • Draw the joystick control on the frame. Change the Joystick1 properties:
    • Display Style: Graphical
    • XMax:  90
    • XMin:  -90
    • YMax:  90
    • YMin:  -90


  • Next add a Timer to the frame. In the properties box, set the Interval to 200.

Code the Timer1_Timer procedure with the following:

Servo.Position(0) = Cint(Joystick1.XPos + 90)
Servo.Position(1) = Cint(-Joystick1.YPos + 90)
Text1 = Servo.Position(0)
Text2 = Servo.Position(1)

Save and run the program again. Move the joystick by clicking and dragging with the mouse. If you have a USB joystick, stop the program, attach to a USB port and wait until it is recognized by the computer. Start the program and try the joystick! Try changing the interval in the Timer1 properties. What effect does it have??

Additional Code

There is a way to make the joystick smoother. Follow these steps:

  • Replace the code in Timer1_Timer with the following:

If (Servo.Position(0) < 180) and (Joystick1.XPos > 20) Then
     Servo.Position(0) = Servo.Position(0) + 1
Elseif (Servo.Position(0) > 0) and (Joystick1.XPos < -20) Then
     Servo.Position(0) = Servo.Position(0) - 1
End If
Text1 =

If (Servo.Position(1) < 180) and (Joystick1.YPos > 20) Then
     Servo.Position(1) = Servo.Position(1) + 1
Elseif (Servo.Position(1) > 0) and (Joystick1.YPos < -20) Then
     Servo.Position(1) = Servo.Position(1) - 1
End If
Text2 = Servo.Position(1)

Save and run the program. Again see what effect the Timer1 Interval has. Also you can experiment with the increment/decrement value. That is try .5 or 2 instead of 1. If you use 2 then change the limits to 1 and 179 from 0 and 180!

2004 CDLI