Joy Stick to Control Camera

Hi guys, I have been working for a week now on this project. The goal is to have a joy stick to control two motors (considering dc and servo motors) so the camera can point to a desired spot. Ideally, the minimum rotation should be less than .5 degrees. I tried using a servo motor, but that shakes the camera a significant amount and the encoders attached to the DC motors seem to skip counts (8246 counts per revolution (if you include that the motors were geared down)) . Sometimes 0, sometimes about 30. I have used the encoder.h class and a couple other methods for counting the encoder and I think I have done the best I could with those.

Right now, I am unsure about what motor I should use. I'm leaning towards the DC motor because at least it is smooth and has an error of at most 2 degrees per revolution. Any advice would be awesome!

Joystick control of a servo is fairly easy using the servo “knob” example in the arduino IDE. If the cam is large, then a balanced mount should be built such that the servo does not hold the cam’s weight.

Gear the motors.

However there is the classic tradeoff in that what you gain in angle resolution you'll lose in maximum speed.

(cheaper) Hobby servos will have a fair amount of jitteriness so that's just a given. But as for the DC motors, how are you controlling them? i.e. what are you doing with the encoder information ?

Ideally, the minimum rotation should be less than .5 degrees. I tried using a servo motor, but that shakes the camera a significant amount

.5 deg is at the resolution limit for typical hobby servos using us control values. Perhaps you should post the code you are using.

.5 deg is at the resolution limit for typical hobby servos using us control values.

With a 1ms to 2ms range of control value this gives us a range of 1000us
Assuming a standard 180° servo angle range - with 0.5° res that is 360 steps

360 ≯ 1000

But yeah, it's not ideal is it :slight_smile:

With a 1ms to 2ms range of control value this gives us a range of 1000us
Assuming a standard 180° servo angle range - with 0.5° res that is 360 steps

360 ≯ 1000

Not sure of the point you are trying to make. The hobby servos I have tested were able to physically rotate ~180-190 deg, and were able to make 426 discrete movements in that rotation range using us control commands. Most hobby servos have an internal ~5us deadband to limit hunting, which also limits movement resolution. These servos had a command range more like 500us to 2500us than 1000us to 2000us. YMMV

if you're not sure what point I'm trying to make then I'm not sure what point you're trying to make when you say:

".5 deg is at the resolution limit for typical hobby servos using us control values."

I was going with the standard spec, but with your numbers:

190/0.5 = 380

2500 - 500 = 2000

If you have a 5us deadband then (and depending on how you interpret it) you have let's say 2000/5 = 400 'values'.

380 400

Not really a point exactly - just saying there is more too it, if you want.

It’s not the 8246 counts per revolution that causes a problem - it is the number per second if the motor is rotating quickly.

Could you mount an encoder on the output shaft rather than on the motor shaft.

Maybe a stepper motor would be more suitable for this application - especially if it is used to drive a screw for positioning the camera. See stepper motor basics.


I was going with the standard spec,

Well, time to get your servo out and do some actual testing. It is easy. To see the servo dead band I attached a 10" bamboo skewer to my servo horn (attached picture), then moved the servo in 1us increments. Looking at the tip of the skewer one can visually see when the servo moves. Check the number of 1us commands between each discrete servo movement. Make sure the servo is secured as it will try to move when it moves the skewer. To check the servo command control rotation range of the servo, I attached a protractor to the servo horn (printable protractor in the link) and used it to measure the full command range of the servo. I did this a long time back with another servo controller and software, but the included servo test code should allow you to do similar testing. Servos can vary in the way they are made and operate, so YMMV. Post the results you get with your servo.

// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a 
// to decrease) and enter to change servo position 
// (two hands required, one for letter entry and one for enter key)
// use strings like 90x or 1500x for new servo position 
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
Servo myservo;
int pos=1500; //~neutral value for continous rotation servo
//int pos=90;

void setup()
  myservo.attach(7, 400, 2600); //servo control pin, and range if desired
  Serial.println("serial servo incremental test code");
  Serial.println("type a character (s to increase or a to decrease)");
  Serial.println("and enter to change servo position");
  Serial.println("use strings like 90x or 1500x for new servo position");

void loop()
  while (Serial.available()) {
    char c =;  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  if (readString.length() >0) {
    if(readString.indexOf('x') >0) { 
      pos = readString.toInt();

    if(readString =="a"){
      (pos=pos-1); //use larger numbers for larger increments
      if(pos<0) (pos=0); //prevent negative number
    if (readString =="s"){

    if(pos >= 400) //determine servo write method
  readString=""; //empty for next input


I’m doing an animatronics project at the mo’ so done a few too, digitals though.

Hitec, JR, Savox and MKS

Mostly higher speed and smaller 6V models - the ranges were reduced presumably because of internal gearing for the speed.

All the specs are online already anyway - but testing as you’ve done suggest (as you do) they are slightly pessimistic (a good thing).

All done via C++ interface to a polulu driver. The JR model wins hands down for deadband characteristics, quietness and speed, but it was the most expensive so go figure :slight_smile: …as for value for money it’s Hitec.

MKS and Savox are both spec and cost wise good too, but just not as note worthy according to my servo sensibilities as the others.

teddyf when you were using servos, how did you supply power to the servo units and did you bypass supplies and joystick inputs to the arduino?
What model arduino are you using, and did you program a deadband into your joystick input part of the program to minimise jitter?
You mention also motors and encoders, can you show us how you connected each of thetwo methods and any code you used.

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7,148850.0.html

Tom..... :slight_smile:

Didn't see it mentioned, but if you're using an understrength servo for the weight of the camera, then it will be jittery. Try looking at stronger servos, there are many hobby level servos that deliver the smooth motion that is demanded of them.

Hi everyone. Thank you for the replies. A lot has happened since this post (I know, its only one day but still). I suspect that the motor was moving to fast causing the encoder skips. The motor was geared down by the ratio 172:1 which would allow the 8246 encoder ticks per revolution. I considered putting an encoder on the actual shaft, however that would give me a 48cpr for the shaft which is far too low of a resolution (and also I need to mount a camera on this). I am going to go with dc motors that have an rpm of .5 and 32 cpr encoders. Hopefully this should avoid any problems with skipping counts but I will have to find out.

Marmotjr: I am using the hitech 5485HB hobby servo which I know is not the most accurate. I tested it already by running code which tested the step size of the motor (more like tested to see if there was any movement of the servo when angle increment was “this” big). However, after using more higher end servos (powered by a power supply), it was noticed that the servo would shake constantly. Not a jitter that would impede normal motion but one that was significant enough to make mounting an hd camera worthless. Our group has decided to pursue dc motors as a result.

The code for the servos and dc motors are posted below. Again thank you all for your help!

TesterServoPS.ino (242 Bytes)

TestEncoder.ino.ino (575 Bytes)

I hope that is not the only servo program you tested with, all that does is sweep back and forth from 0 to 180 in 10Deg 50mS steps.
At no time is the servo commanded to stop.
So how can you say you had jitter?

Tom..... :slight_smile:

Hi Tom:

If that's the code I think I used to test (managing 40 files for this project and I'm not the most organized...) I kept changing the degrees to check accuracy. When running it on a hobby servo, the range was far greater than 180, more like 200 and the servo rarely reached the correct angle (30 appeared like 5 etc). I tested this with a more high end pan and tilt system and found that the motors would shake ever so slightly but enough to mess with the camera. Either way our group has decided to work with do motors and encoders which should be smoother.

Fine, if you have the servo under load then you will probably have some jitter, video wise not good.
The DC motor and encoder will give you more parameters to play with, including the step/turn, speed and torque.

Tom...... :slight_smile:

I looked at the pan/tilt picture and the pan/tilt design will probably wiggle and shake on its own (especially if the cam has any weight) . You might look at the servocity pan/tilt units for ideas. For large cams good bearings should be used in the pan/tilt structure and the cam should be balanced in the mount such that any weight is supported by the mount and not by the servos or motors.

Edit: also cheap joysticks may require dead bands in the code to prevent hunting due to slop or noise in the joystick pots.

Hi zoomkat. The pic of the pan and tilt system was just the system I have been using for testing (dc motors). The servo system I used was actually from servo city I believe (I would post picture but I currently don't have access to it), but it was a far nicer setup. I will keep your advice when building our final model. Thanks for the help!