Servo motor programming

Hello everyone,
I have a HS-7950TH servo with a SPG7950A-360 top mount Servo Power Gearbox from Servocity. I am trying to interface the servo with an Arduino Uno and rotate the servo in 5 degree increments. I am giving the input using a standard 4*4 keypad and reading the angle on an LCD. There are two problems I am facing:

  1. The servo seems to rotate continuously when given an input angle below 34 degrees or above 150 degrees. It works fine between these limits. I just need to use it in a certain range so I can work around this problem. But any reason as to why this is happening will be appreciated.
  2. The other problem I am facing is that the gears seems to be a 1:4 ratio. So, an angle input of 5 degrees gives a displacement of approx. 20 degrees to the output shaft. So, to give a displacement of 5 degrees to the output shaft, I need to rotate the servo by approx. 1.25 degrees which is not possible by using the arduino servo library. Is there a better way to do this?

P.S.: I am using the defualt servo library in Arduino and using the functions writeMicroseconds() and servo.write() to achieve the output.

Here's a link to the servo I am using:
http://www.servocity.com/html/spg7950a-360_360o_rotation.html

The link you posted says that the two extreme positions of the servo are 1100 and 1900 microseconds. That sounds very normal.

If it doesn't work according to the spec I think you need to ask the suppliers.

...R

Does the servo continue to rotate more than four turns when you say "seems to rotate continuously "? It appears the servo gear setup has a ~four turn pot attached to the bottom (might lower actual position resolution). What is the max degree rotation you will need in your project? Below is a simple setup I used to measure the position resolution of a standard servo. Bottom is some servo test code setup to use a degree input value or a microsecond value from the serial monitor.

// 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*.

#include<Servo.h>
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.begin(9600);
  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");
  Serial.println();
}

void loop()
{
  while (Serial.available()) {
    char c = Serial.read();  //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"){
      (pos=pos+1);
    }

    if(pos >= 400) //determine servo write method
    {
      Serial.println(pos);
      myservo.writeMicroseconds(pos);
    }
    else
    {   
      Serial.println(pos);
      myservo.write(pos); 
    }
  }
  readString=""; //empty for next input
}

jeet_14:
2. The other problem I am facing is that the gears seems to be a 1:4 ratio. So, an angle input of 5 degrees gives a displacement of approx. 20 degrees to the output shaft. So, to give a displacement of 5 degrees to the output shaft, I need to rotate the servo by approx. 1.25 degrees which is not possible by using the arduino servo library. Is there a better way to do this?

P.S.: I am using the defualt servo library in Arduino and using the functions writeMicroseconds() and servo.write() to achieve the output.

If you are using writeMicroseconds() to set the servo position then you are not specifying the position in degrees so I don't understand why you are referring to problems caused by setting the position in degrees. Setting the position in microseconds as you are doing gives you much better resolution than setting it in degrees, and is the sensible approach in your situation. In order to set the position in microseconds you will need to calculate the microsecond value corresponding to the required physical servo position. To do that you need to identify two end points that contain the whole range of travel that you need, and find the corresponding microsecond values, and estimate the angular difference between the end points. Then you can map any position within that range to the corresponding microseconds value..

@zoomkat:
I was trying to set the initial position with writemicroseconds() and then rotating the servo by the angle. But using writeMicroseconds() for the rotation was the correct approach. I only wanted a 20 degree rotation and figured out the corresponding microsecond value.
Thanks for your input. The code really helped finding the corresponding values.

@PeterH:
I should have used writeMicroseconds() from the start itself. The 0 degree angle is outside the 1100 microsecond range specified in the specifications of the motor and probably is why the motor keeps spinning continuously.