Can someone tell me if my understanding is correct please.

The control signal to a hobby servo motor that is connected to an arduino operates by :

In every 1 s there are fifty windows each of length 20ms. Thus the frequency is 50 Hz right ?

Moving on,

If the servo shaft is at its center and I want it to go 90 degrees left, in each of the 20ms of the 1s, the PWM pin will generate a PWM signal that has 1 ms of pulse width until the pulse has traveled for 1s and then for the next second generate something like 1.25ms?

or will it start at 1 ms and during that 1 s period and change from 1ms to a different value 1.25 ms and 1.5ms as it comes closer and closer to the desired angle( decreases in angle ) ?

  • 1
    \$\begingroup\$ Position is proportional to the width of the pulse. There is a width associated with center. A shorter width will move it to a position to one side of center, and a longer pulse will move it to the other. So long as you keep the pulse width constant, the servo will hold that position \$\endgroup\$ Commented Apr 6, 2015 at 1:46
  • \$\begingroup\$ Hey thanks. I wanted to clarify that too. But i was really focusing on the travel. Will the pulse width decrease in each pulse within that 1s as it travels to the desired position. E.g 0 to -90. Will it gradually decrease from sending 1ms in one 20ms window and 1.25ms in the other window and 1.27ms etc within that 1s pulse train ? \$\endgroup\$ Commented Apr 6, 2015 at 2:49
  • 3
    \$\begingroup\$ You send the pulse. "It" doesn't. \$\endgroup\$ Commented Apr 6, 2015 at 10:31

2 Answers 2


The hobby servo needs a signal like this:

In a 20ms window, (50 times a second) a pulse with a width between approximately 1ms and 2ms (may vary, depending on servo) with a middle point of 1.5ms. So in the 20ms window, there is almost 90% of the time being "silence" with no signal level. The pulse is only high for a very short (relatively) period.

The Arduino pins are default output to either 500Hz and 3.9Khz. You cannot directly use the pin in PWM mode (with analogWrite), because it will be receiving pulses too fast, and will bug out/malfunction/won't do anything useful.

The Servo library available for inclusion to an Arduino sketch uses the built-in timers of the ATMEGA328P (or other chip, depends on which arduino you are using) and some fancy software and interrupts to get the proper 50Hz timing, and uses an ordinary digital output pin to send the required pulse.

You can do this yourself in a simple loop, if you only control 1 servo and have a simple program, by simply setting a digital pin HIGH and then delaying (using DelayMicroeconds) for between 1000 and 2000 microseconds depending on what position you want to move to, then setting the pin LOW and delaying for (20,000 - the time you delayed for the servo).

You can send the same signal constantly and the servo will stay at that point, or you can send it until it reaches there and stop sending a signal. The servo should stay at that point, but I do not think it will remember the point (you can move it with your hand and it will stay at the new point, until a new signal is sent again).

It's better not to try and use the PWM hardware outputs for the Arduino to control a servo, even if you do manage to pre-scale the timers down to the required 50Hz (I think this would be hard to get, but I believe you can do it!) as the PWM output registers will need to be set with 8 bit resolution in a tiny range of 10-20%, which only gives you 25 total positions available to the servo (that is pretty bad, 25 positions for a whole +-90 degree movement range!). So go with the Servo Library, basically :)

  • \$\begingroup\$ Hey, what I understand is that you want 90 degrees you input 90 in your sketch and it sends a 1ms pulse in every 20ms window, when it reaches 90 degrees (or its desired position) it keeps sending out the 1ms to hold it at that position. If it wants to go 90 degrees the other way it will send a pulse of 1.5ms in all the 20ms windows and when it reaches at that point it will still send that pulse to hold it there. Is that how it works ? I will like to eventually control the DC motor inside with an H-bridge and the 8 bit pwm of my microcontroller later on... \$\endgroup\$ Commented Apr 7, 2015 at 2:28
  • \$\begingroup\$ @IsaiahDeFreitas "If it wants to go 90 degrees the other way it will send a pulse of 1.5ms " no, 90 degrees the other way is 2ms. 1.5ms is the "middle" remember? \$\endgroup\$
    – KyranF
    Commented Apr 7, 2015 at 2:44
  • \$\begingroup\$ @IsaiahDeFreitas there is already an H bridge inside the servo control unit. You should just go buy a little 6V DC brushed DC motor yourself and do your own position-based feedback system the same way as a servo, but without the stupid 20ms/50Hz crap \$\endgroup\$
    – KyranF
    Commented Apr 7, 2015 at 2:45
  • \$\begingroup\$ how does the comparator circuit chip inside the casing work ? \$\endgroup\$ Commented Apr 7, 2015 at 17:02
  • \$\begingroup\$ @IsaiahDeFreitas just read this, it will explain all! pcbheaven.com/wikipages/How_RC_Servos_Works It doesn't actually describe the circuit for the input signal decoding though \$\endgroup\$
    – KyranF
    Commented Apr 7, 2015 at 18:36

Neither. The pulse given will determine the position, and you do not have to gradually change the position from one value to another.

You will go from neutral position to 90 position, at the speed of the servo.

The standard arduino servo library does not gradually change the values from one period to the next. Whatever you push out will be sent immediately, unless you decide to send out gradually changing values. And those values can be changed in a single period if you want.

  • \$\begingroup\$ so inside the controller circuit it does not decrease its pulse width as it comes closer to the desired position ? Also what pulse is sent when it reaches its desired position ? \$\endgroup\$ Commented Apr 7, 2015 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.