Maker Pro
Maker Pro

Arduino Pan and Tilt


Apr 16, 2012
Apr 16, 2012
Hello, I am working on 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.

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