Arduino Servo Calculator (Angle to Pulse Width)
NOUVEAUArduino servo calculator: convert servo angle to pulse width and back, get the 50 Hz duty cycle and PCA9685 tick count, plus Servo.h code.
Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.
Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.
PCA9685: prescale 121 → actual 50.029 Hz, 1 tick = 4.88 µs. Servo.write() takes an integer angle 0–180, maps it with integer map() and so can be up to one step off the ideal pulse.
| angle | pulse µs | write() | duty % | ticks |
|---|---|---|---|---|
| 0° | 544 | 544 | 2.72 | 111 |
| 30° | 853.33 | 853 | 4.267 | 175 |
| 60° | 1162.67 | 1162 | 5.813 | 238 |
| 90° | 1472 | 1472 | 7.36 | 302 |
| 120° | 1781.33 | 1781 | 8.907 | 365 |
| 150° | 2090.67 | 2090 | 10.453 | 428 |
| 180° | 2400 | 2400 | 12 | 492 |
Arduino code
// ── Option 1: Servo library on a PWM-capable pin ──
#include <Servo.h>
Servo servo;
void setup() {
servo.attach(9, 544, 2400); // pin, min µs, max µs
servo.writeMicroseconds(1472); // 90°
// or: servo.write(90); (write() maps 0..180 onto 544..2400 µs)
}
void loop() {}
// ── Option 2: PCA9685 16-channel driver (Adafruit_PWMServoDriver) ──
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm; // I2C address 0x40
void setup() {
pwm.begin();
pwm.setOscillatorFrequency(25000000); // trim to your board, often 25–27 MHz
pwm.setPWMFreq(50);
pwm.setPWM(0, 0, 302); // 1472 µs ≈ 302 ticks
}
void loop() {}Power servos from a separate 5–6 V supply with a common ground, not from the Arduino 5 V pin — a stalled servo can draw over 1 A. Check your servo's datasheet for its safe pulse range before driving it to the end stops.
Exemples rapides
Des entrées typiques et les résultats produits par cet outil.
Présentation
Hobby servos are positioned by the width of a pulse repeated about 50 times per second: roughly 1 ms at one end, 1.5 ms in the middle and 2 ms at the other end. The Arduino Servo library uses a wider default of 544–2400 µs for 0–180°, while many servos only accept 1000–2000 µs, and the PCA9685 driver board needs the pulse expressed as a 12-bit tick count instead of microseconds.
This Arduino servo calculator converts an angle to a pulse width (or a pulse width to an angle) for any range, shows the duty cycle at your frame rate, the value Servo.write() really sends after its integer map(), and the PCA9685 prescale, real output frequency and tick count. A table covers the whole travel and the generated sketch works with both Servo.h and Adafruit_PWMServoDriver. All calculations run in your browser.
Pourquoi utiliser cet outil ?
- Servo.h, standard RC and custom pulse ranges
- PCA9685 prescale and tick values without guesswork
- Shows the integer rounding of Servo.write()
- Angle table for the full servo travel
- Free, offline-capable and private
Fonctionnalités
Angle ↔ pulse width
Linear conversion between degrees and microseconds for 180°, 270° or any travel.
Duty cycle
Duty cycle in percent at 50 Hz or any frame rate you enter.
PCA9685 ticks
Prescale, actual frequency, µs per tick and setPWM() off value with a trimmable oscillator.
Servo.write() check
Reproduces the library’s integer map() so you see the pulse it really outputs.
Travel table
Pulse, duty and ticks for every step from 0° to full travel.
Code snippet
Copy Servo.h and Adafruit PCA9685 code with your numbers filled in.
Mode d'emploi
Pick the pulse range
Choose Servo.h default, standard RC, wide or enter custom min/max microseconds.
Enter angle or pulse
Switch between Angle → pulse and Pulse → angle and type the value.
Adjust PWM settings
Set the frame rate and, for PCA9685 boards, the oscillator frequency.
Copy the code
Read the results and table, then copy the generated sketch.