PWM Duty Cycle Calculator

Convert duty cycle % to Arduino analogWrite and ESP32 LEDC values, and get period, on-time, off-time and average voltage with a live waveform.

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

How to use the PWM duty cycle calculator

  1. Type a value into any one of the duty boxes — duty cycle in %, the Arduino analogWrite() value (0–255) or the ESP32 ledcWrite() value. The other boxes update instantly.
  2. Pick the ESP32 LEDC resolution (8 to 14 bits) you use in ledcAttach().
  3. Choose a board/pin preset or type your own PWM frequency, and enter the supply voltage (5 V for an Uno, 3.3 V for an ESP32).
  4. Read the period, on-time, off-time and average voltage, check the waveform, and copy the ready-made code line.

Formula

PWM (pulse-width modulation) switches a pin fully on and fully off very quickly. The duty cycle D is the fraction of each period that the pin is HIGH.

T = 1 ÷ f t_on = D × T t_off = T − t_on V_avg = D × V_supply analogWrite value = D × 255 ledcWrite value = D × (2^bits − 1)

The calculator rounds the register values to whole numbers and shows the duty cycle you actually get.

Default PWM frequencies

BoardPWM pinsFrequencyResolution
Arduino Uno / Nano3, 9, 10, 11490.2 Hz (16 MHz ÷ 64 ÷ 510)8-bit, 0–255
Arduino Uno / Nano5, 6976.6 Hz (16 MHz ÷ 64 ÷ 256), often quoted as 980 Hz8-bit, 0–255
ESP32 (LEDC)almost any output GPIOyou choose it in codeup to 14 bits on every ESP32 chip (20 on the original ESP32)
Raspberry Pi Picoany GPIOyou choose it in codeduty_u16() takes 0–65535 in MicroPython

On the ESP32 the LEDC timer runs from an 80 MHz clock, so frequency × 2^bits must stay below 80 MHz. That gives about 312.5 kHz at 8 bits, 78.1 kHz at 10 bits, 19.5 kHz at 12 bits and 4.88 kHz at 14 bits.

Average voltage is not a real analog voltage

The pin is always either 0 V or fully HIGH. A motor, an LED (as seen by your eye) or a multimeter averages the pulses, so they behave as if the voltage were D × V_supply. If you need a smooth voltage — for example to feed an op-amp — add an RC low-pass filter and size it with the RC filter cutoff calculator.

Choosing a PWM frequency

  • LED dimming: a few hundred Hz or more. Below about 100 Hz the flicker becomes visible, especially on camera.
  • DC motors: a few kHz works; 20 kHz or above is silent but check your driver's maximum switching frequency.
  • Hobby servos: do not use plain PWM. They need a 50 Hz pulse of about 0.5–2.5 ms — use the servo pulse width calculator.

Common mistakes

  • Using a non-PWM pin. On an Uno only pins 3, 5, 6, 9, 10 and 11 (marked ~) give PWM. On other pins analogWrite() just turns the pin fully on (value ≥ 128) or off.
  • Writing 255 on a 12-bit ESP32 channel. That is only 6% duty. Full scale is 4095 at 12 bits — always match the value to the resolution.
  • Changing Timer0 on the Uno. Pins 5 and 6 share Timer0 with millis() and delay(), so changing its prescaler breaks timing.
  • Servo library clash. On the Uno the Servo library uses Timer1, so analogWrite() stops working on pins 9 and 10.
  • Forgetting the LED resistor. PWM does not limit current — size it with the LED resistor calculator.

Want the full story with experiments? Read PWM explained: LED dimming and motor speed, compare boards in Arduino vs ESP32 vs Raspberry Pi Pico, or pick up an Arduino or ESP32 kit from our kits page.

Frequently asked questions

How do I convert duty cycle to an analogWrite value?+

Multiply the duty cycle (as a fraction) by 255. For 25% duty, 0.25 × 255 = 63.75, so use analogWrite(pin, 64). A value of 0 is always off and 255 is always on.

What is the default PWM frequency of an Arduino Uno?+

About 490 Hz on pins 3, 9, 10 and 11 (exactly 16 MHz ÷ 64 ÷ 510 = 490.2 Hz) and about 980 Hz on pins 5 and 6 (exactly 976.6 Hz). The Nano behaves the same because it uses the same ATmega328P chip.

What value do I pass to ledcWrite on an ESP32?+

It depends on the resolution you set in ledcAttach(). At 8 bits full scale is 255, at 10 bits 1023 and at 12 bits 4095. Multiply the duty cycle by that full-scale number, so 50% at 12 bits is about 2048.

How do I calculate the average voltage of a PWM signal?+

Multiply the duty cycle by the HIGH voltage: V_avg = D × V_supply. A 5 V signal at 40% duty averages 2 V. The pin still switches between 0 V and 5 V, so add an RC filter if you need a smooth voltage.

What is the highest PWM frequency on the ESP32?+

The LEDC timer runs from an 80 MHz clock, so frequency × 2^bits must stay below 80 MHz. That allows about 312.5 kHz at 8 bits, 78 kHz at 10 bits and 19.5 kHz at 12 bits. Higher resolution means a lower maximum frequency.

From the Thinking Robot store

Shop all
All tools
WhatsApp