Servo not centering at 90° - after calibration


I calibrated a servo for (more or less) exact 0° and 180° position using the min/max timing options when attaching the servo (using the servo library).
When I now move it to 90° it doesn't center but is off by estimated 3°.

I would like to get this more exact as I use it for moving a IR sensor to map the environment. Is there a way to improve this situation or is it simply the inaccuracy of the hardware?


Good question.

The accuracy by the Arduino is 255 steps. I don't think you can improve that with the functions of the library.
The linearity of the potentionmeter in the servo could be 10% inaccurate for very cheap ones.
Which servo motor do you use ? Can you post a link to it ?

Perhaps your project requires a stepper motor ?

Are you using servo.writeMicroseconds(uS)
That should give you about 1000 steps.

From memory, the internal tick size of the servo library is 4us so 1000 to 2000 us pulsewidth gives 255 steps even when using writemicroseconds.

As for the calibration i would use the map function with a separate mapping for 1000 to center and center to 2000. If you manually figure out what the center is, you should be good with this approach

Duane B


the servo is a GoTeck gs-9025mg. The two different mappings is a good idea. I also have a 28BYJ-48 lying arround. I'll give this a try. If it gets too complicated I'll go for the mapping approach.

Thanks for your answers.

I can't find accuracy specifications for that servo.

Is that a stepper motor with a gear ? The accuracy seems to be 0.08 degrees per full step (but I'm not sure).

Here is the same problem,

I have not (yet) experimented with the “absolute” positioning accuracy of servos. Consider that they really were meant as part of a system where a human operator constantly adjusts it - not beause of the position the servo has taken, but the effect it has (eg on the model airplane). Absolute or linear accuracy is therefore not needed.

I have had a similar problem driving a big analog meter with PWM. It did not respond linearily (presumably some resonace effect between the coil, the mechancs and the 400Hz PWM). I therefore manualy noted the PWM value that would place it at some points, and when driving it used the values as lookups with a linear interpolation between. Worked for me. You could try the same approach.

You should follow Msquare's method and build a simple calibration table. Linear angular accuracy is not a priority with hobby servos.

Be aware the IR reflectivity varies between materials. IR distance sensors that I have tried are also quite non-linear with a different curve for different materials. The sensor may be a bigger headache than the servo. You may also want to try ultrasonic sensors. Of course a laser rangefinder would be nice :slight_smile: