Calculator

Enter your target values. Results and code update as you type.

Target PWM frequency. Enter a frequency greater than 0.
0–100%. Enter a value between 0 and 100.
1–16 bits. Higher = finer duty steps, lower max frequency. Enter a whole number from 1 to 16.
0–15. Enter a whole number from 0 to 15.
The output-capable GPIO the LED/motor/servo is wired to. Enter a whole number from 0 to 39.
Duty value (raw)
128 / 255
Max resolution at this frequency
13 bits
Max frequency at this resolution
312500 Hz
Arduino code
const int pwmPin = 18;
const int pwmChannel = 0;
const int frequency = 5000;
const int resolution = 8;

void setup() {
    ledcSetup(pwmChannel, frequency, resolution);
    ledcAttachPin(pwmPin, pwmChannel);
    ledcWrite(pwmChannel, 128);
}

void loop() {

}

Examples

Pick a preset to populate the calculator above.

About this tool

What is ESP32 LEDC PWM?

LEDC is the ESP32's hardware PWM peripheral. It was originally built for LED dimming, but it can drive anything that needs a pulse-width-modulated signal — motors, servos, buzzers and simple audio. LEDC generates the signal in hardware on a chosen channel and GPIO, so it runs independently of your main program loop.

What this calculator does

Frequency and resolution share the same hardware timer, so raising the resolution lowers the maximum frequency you can hit, and vice versa. This calculator checks your frequency against the maximum achievable at your chosen resolution, converts your duty cycle percentage into the raw duty value LEDC expects, and generates the matching ledcSetup / ledcAttachPin / ledcWrite calls so you can paste them straight into a sketch.

Why it's useful

  • Avoids silently-clamped frequencies caused by picking an incompatible resolution.
  • Removes the manual duty-cycle-to-raw-value math.
  • Gives you copy-ready code instead of hand-typing constants.

Who should use it

Anyone wiring an LED, motor, servo or buzzer to an ESP32 and using the Arduino core's LEDC functions — from a first prototype on a breadboard to production firmware that needs a known-good starting configuration.