A hobby servo moves to the angle encoded in the width of a short pulse, repeated about fifty times a second. To aim it, you need the pulse width in microseconds for the angle you want, and often the matching duty cycle or timer compare value for the microcontroller. This calculator converts a target angle into all three, and estimates how long the move takes.
How the calculation works
- Pulse width = minimum pulse + angle ÷ full travel × (maximum pulse − minimum pulse)
- Duty cycle = pulse width ÷ signal period × 100
- 16-bit compare value = duty cycle × 65,535
- Resolution = full travel ÷ (maximum pulse − minimum pulse), in degrees per microsecond
- Move time = angle change ÷ 60° × seconds per 60°
Example
A servo with 180° of travel and a 1,000 to 2,000 µs pulse range is sent to 90° at 50 Hz. The pulse is 1,500 µs, the duty cycle 7.5 % of the 20 ms period, and a 16-bit timer needs a compare value of about 4,915. One microsecond moves the horn 0.18°. Moving from 0° to 90° at 0.15 s per 60° takes 0.225 s.
Why it matters
A wrong pulse range is the most common cause of a jittery or stalled servo. Working out the pulse for each angle lets you set the limits in your code, avoid the end stops and move smoothly between positions. Knowing the move time also tells you how long to wait before the next command in a robot arm or a pan-and-tilt mount.
Good to know
Cheap servos vary from one unit to the next, so the 1,000 and 2,000 µs limits are typical but not guaranteed. Digital servos may accept higher refresh rates, such as 200 or 333 Hz. A servo holding a load draws more current than one at rest, so give it a power supply that is separate from the microcontroller. This tool is for education.
Related tools
The PWM duty cycle calculator converts a duty cycle into average voltage, the 555 timer calculator sets a pulse width with a resistor and capacitor, and the stepper motor steps calculator handles open-loop positioning.