Servo Pulse Width Calculator

Convert servo angle to pulse width (µs) and back for SG90 and standard servos, with duty cycle, writeMicroseconds and ESP32 LEDC values.

  • Free, no signup
  • Works on mobile
  • Formula + worked example

How to use the servo pulse width calculator

  1. Choose your servo type. SG90 / MG90S micro servos usually need about 500–2500 µs for their full travel; many standard servos use 1000–2000 µs. Pick Custom to enter your own limits.
  2. Check the travel (usually 180°) and the signal frequency (50 Hz for almost every hobby servo).
  3. Type an angle (or drag the slider) to get the pulse width — or type a pulse width to see which angle it gives.
  4. Copy the writeMicroseconds() value for the Arduino Servo library, or the ledcWrite() value for an ESP32 at the resolution you choose.

How a servo signal works

A hobby servo does not care about the duty cycle as such. It measures how long each HIGH pulse lasts, and repeats that measurement every 20 ms (50 Hz). A 1.5 ms pulse means "go to the middle"; shorter pulses turn one way, longer pulses the other way.

Formula

pulse (µs) = min + (angle ÷ travel) × (max − min) angle = (pulse − min) ÷ (max − min) × travel period T = 1 ÷ f (50 Hz → 20 ms = 20,000 µs) duty = pulse ÷ T ESP32 ledcWrite value = duty × 2^bits

Angle to pulse width table (50 Hz)

AngleSG90 (500–2500 µs)DutyStandard (1000–2000 µs)DutyArduino write() default
0°500 µs2.5%1000 µs5%544 µs
45°1000 µs5%1250 µs6.25%1008 µs
90°1500 µs7.5%1500 µs7.5%1472 µs
135°2000 µs10%1750 µs8.75%1936 µs
180°2500 µs12.5%2000 µs10%2400 µs

The last column shows what myServo.write(angle) sends when you call attach(pin) without limits: the Arduino Servo library maps 0–180° to 544–2400 µs.

ESP32 resolution matters

At 50 Hz the period is 20 ms, and the LEDC splits it into 2^bits steps. At 8 bits one step is 78 µs, which is about 7° on an SG90 — far too coarse. Use 14 bits (works on every ESP32 chip) or 16 bits on the original ESP32. Note that the standard Arduino Servo.h library does not support the ESP32; use LEDC directly or the ESP32Servo library.

Common mistakes

  • Using analogWrite() for a servo. Arduino PWM runs at 490 or 980 Hz, which a servo cannot understand. Use the Servo library or a 50 Hz LEDC channel — see the PWM duty cycle calculator for the difference.
  • Forgetting the limits in attach(). Without them, writeMicroseconds() is clamped to 544–2400 µs and an SG90 never reaches its full travel.
  • Driving into the end stops. A buzzing servo at 0° or 180° is pushing against its stop, getting hot and wearing its gears. Reduce the range a little.
  • Losing PWM on pins 9 and 10. On an Uno the Servo library uses Timer1, so analogWrite() no longer works on those pins.
  • No common ground between the servo supply and the microcontroller — the signal then has no reference and the servo jitters.

Learn the full wiring and code in our SG90 servo motor Arduino guide. Building a robot arm or a pan-tilt head? Work out the gearing with the gear ratio calculator, find project ideas in school science exhibition robotics projects, and get servos and boards in our robotics kits.

Frequently asked questions

What pulse width moves a servo to 90 degrees?+

About 1500 µs (1.5 ms) for almost every hobby servo. That is the centre position. For an SG90 using 500–2500 µs, 0° is 500 µs and 180° is 2500 µs; for a standard 1000–2000 µs servo, 0° is 1000 µs and 180° is 2000 µs.

What is the duty cycle of a servo signal?+

At 50 Hz the period is 20 ms, so the duty cycle is pulse ÷ 20 ms. A 1.5 ms pulse is 7.5%, 0.5 ms is 2.5% and 2.5 ms is 12.5%. The servo reads the pulse length, not the percentage, so always think in microseconds.

Why doesn't my SG90 turn a full 180 degrees?+

The Arduino Servo library uses 544–2400 µs by default, and many SG90s need about 500–2500 µs for full travel. Use myServo.attach(pin, 500, 2500) and calibrate the ends slowly, stopping before the servo buzzes against its end stop.

How do I control a servo with ESP32 LEDC?+

Set a 50 Hz LEDC channel with 14-bit resolution, then write duty × 16384. For 1500 µs that is 1500 ÷ 20000 × 16384 ≈ 1229. The standard Arduino Servo.h library does not support the ESP32, so use LEDC or the ESP32Servo library.

Can I power a servo from the Arduino 5 V pin?+

One small SG90 with no load may work, but it is not recommended. Servos draw several hundred mA when they start or stall, which can reset the board. Use a separate 5 V supply and connect its ground to the Arduino GND.

From the Thinking Robot store

Shop all
All tools
WhatsApp