Sunday, April 8, 2012

Pan and Tilt Mechanism with 2 Parallax Servos and an Arduino

Here is an Arduino controlled pan and tilt mechanism. 

I used two parallax hobby servos available at Radio Shack. I could have ordered some specialty brackets online, but I have little patience. 

I soldered some header pins onto a perf board for connecting the servo plugs to a prototyping board.

Here is a wiring diagram...  

Control is allowed with 2 100K ohm potentiometers ..  I think ultimately I will connect it to an analog thumbstick that has been collecting dust for a while.

The code is based on the Arduino Knob example program.
// Code to allow the arduino to control 2 servos independently  ..
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
Servo myservo1;
int potpin = 0;  // analog pin used to connect the potentiometer
int potpin1 = 1;
int val;    // variables to read the value from the analog pins
int valu;
void setup()
  myservo.attach(9);  // attaches the servo on pin 9 and 10 to the servo object
void loop() 
  val = analogRead(potpin);            // reads the value of the potentiometer
   valu = analogRead(potpin1);
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo s
   valu = map(valu, 0, 1023, 0, 179);     
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there


1 comment:

  1. Good article, very beautiful and useful for me ..... thank you comrade information ......