ESP32 LEDC PWM Calculator
Work out a valid frequency, resolution and duty cycle for the ESP32's LEDC peripheral, then copy ready-to-paste Arduino code.
Calculator
Enter your target values. Results and code update as you type.
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.