Write its mapping range for servos?

Hello Servo.h, puts a constraint on the amplitude of the range of action of the servos:

#define MIN_PULSE_WIDTH 544
#define MAX_PULSE_WIDTH 2400

The reality is different, I just tested 4 servos and here is the result:

Servo N ° 1 MIN_PULSE_WIDTH = 680 MAX_PULSE_WIDTH = 2200

Servo N ° 2 MIN_PULSE_WIDTH = 1000 MAX_PULSE_WIDTH = 1500

Servo N ° 3 MIN_PULSE_WIDTH = 632 MAX_PULSE_WIDTH = 2060

Servo N ° 4 MIN_PULSE_WIDTH = 752 MAX_PULSE_WIDTH = 2248

In order to determine the length of the range in degrees of my servos, do you think that it is possible to map the values defined in Servos.h? If I'm not mistaken:

544 = 0 ° 2400 = 180 ° 1500 = 90 °

Thanks for your help.

Best regards

Have you looked at using the min and max pulse width parameters in the attach() function ?

I tried the code below, but I can not change it to get the result:

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

void setup()
  myservo.attach(10, 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 = 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"){

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

I think that you are misunderstanding the use of the parameters. I believe that when used they cause the servo movement to be mapped such that 0 degrees is equivalent to the min value and 180 degrees is equivalent to the max value when using the write() function.

Using writeMicroseconds() does not use the parameters

I do not understand :

myservo.writeMicroseconds (pos);

2400 is always equal to 180 °.

If you use writeMicroseconds() the value given is used directly to create the signal sent to the servo. Angles have nothing to do with it.

If you use write(angle) then that angle is converted into a pulse width in microseconds, based on the MIN and MAX pulse widths either the defaults or the ones you specify in attach(). So if in attach you say attach(pin, 1000, 2000) then write(0) gives a pulse width of the 1000, write(180) gives 2000.

The angle that the servo actually moves has very little to do with any of this. There are some servos that only move 120 degrees total, others will do 180 and sail winch servos may move over 1500 degrees, all from write(0) to write(180).


It is not possible to know if a servo has a range going for example from 5 ° to 150 ° knowing the real values mini and maxi pulse?

By experiment.

nerixs: It is not possible to know if a servo has a range going for example from 5 ° to 150 ° knowing the real values mini and maxi pulse?

Not unless the manufacturer provides a full specification of the servo or you determine the relationship between pulse width and rotation angle yourself

What do you think about this:


It looks like a way of driving one servo

Exactly what problem are you trying to solve ?

Since this method does not use Servo.h and the ends really meet the values

int lenMicroSecondsOfPulseStart = 0.5 * 1000; // 0 degrees
int lenMicroSecondsOfPulseEnd = 2.2 * 1000; // 180 degrees

I was hoping it was possible to calculate the range.

From your original post it seems that you already know what microseconds values relate to the travel end points of your servos and presumably you know what their range of travel is although it may not be 180 degrees.

So, what problem are you trying to solve ?

No, it's this range of motion (in degrees) that I want to find. Sorry if I did not make myself understood.

Why not use the Knob example that comes with the Servo library and simply measure it ?

When you talk about measuring it, do you talk about a physical measurement with an angel protractor? Knob uses a potentiometer as can it help me?

For goodness sake.

You want to know the angular range of the servo so just measure it with a protractor. The pot is just a means of moving the servo through its range. If you use writeMicroseconds() instead of write() in the Knob program you can ensure that the servo moves through its full range

The difficulty with physical measurement is the point of reference and how to define it? The middle, but where exactly is it? Depending on the position I find: (5 ° to 155 °) or (7 ° to 157 °) or (9 ° to 159 °) ... .. Which is the correct one ?

Is this a wind up ?

The middle of the movement range is half way between the end positions, It is up to you what you designate as the zero position or, indeed, whether there is in fact a zero position at all.

Position the servo in the middle of its range and designate that as the mid point. Does it move equally in both directions to the end of its range ? If not then you are in a world of pain because the movement is non linear. If the movement is equal both ways then you now know the mid point, the two end points, the microsecond value for the mid point and range of movement for a given range of microsecond input. You may, of course, get different results for each servo. What else do you want to know ?

As a matter of interest what are these servos controlling ?

I cross you have identified the problem An example: Servo N ° 1 MIN_PULSE_WIDTH = 680 MAX_PULSE_WIDTH = 2200 I position the servo a (2200-680) / 2 = 760 which is supposed to be the middle. I run a scan is the MIN_PULSE_WIDTH and MAX_PULSE_WIDTH do not match the starting value!