Servo pulse width range with Arduino
I recently bought a couple of cheap MG996R high-torque servos on ebay, and I want to use them with my Arduino.

These have the “JR” servo pinout, so orange = signal, red = V+, brown = V-.
You control these servos by sending a 50Hz pulse width modulated signal. The pulse width determines the position of the servo. Arduino wraps this in a nice Servo library. So you can just use servo.write(<angle>) to set the servo to a certain angle. Cool!
The servo library defaults to pulsing 544ms to 2400ms for angles zero to 180. This is too wide for the MG996R, the servo only moves when you write angles through 20-150 or so. Setting the value outside this range stresses the servo and can wear it out!
I wrote a quick sketch to interactively find the real minimum and maximum values: . You just watch the serial port and follow simple prompts:

Using that sketch, I found my MG996R servos to have minimum pulse width around 771 and maximum around 2193 when running off 5v1. The full sweep is approximately 0-130 degrees.
So, to use the servo library with correct angles the sweep will be 771 to 17982. So I can call:
servo.attach(servopin, 771, 1798); servo.write(0); // Min delay(2000); servo.write(65); // Midpoint delay(2000); servo.write(130); // Max
Yay Arduino!

October 5th, 2010 at 9:18 am
Great info on how to find the min and max on my servo as the mfg’s docs do not seem to be accurate.
I’ll give this a try tonight.
March 12th, 2012 at 9:35 am
And for angle 0 to 180 ? i can’t rotate it to 180…..
March 12th, 2012 at 8:16 pm
Marius – the 0 and 180 are arbitrary, they get mapped to the pulse width values min and max that you provide. So if your servo can move further than 180 when running the test sketch, you should be able to map it. If it doesn’t move further thne it’s probably incapable, at least with the voltage & PWM frequency that the Arduino is providing.
Hope this makes some sense. :)