Concept explainer · Beginner · 3 min read
PWM Explained
Duty Cycle, Frequency and How to Use It
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
PWM (pulse-width modulation) switches a pin fully on and off very quickly; the share of time it is on, the duty cycle, sets the average power. 50% duty on a 5 V pin acts like 2.5 V for an LED or motor. Arduino's analogWrite() gives 8-bit PWM at about 490 Hz; the ESP32 and Pico let you set both frequency and resolution.
Key specs at a glance
- Duty cycle
- On time as a percentage of the period, 0 to 100%
- Frequency
- Pulses per second; Arduino Uno default 490 Hz (980 Hz on pins 5 and 6)
- Resolution
- 8-bit (0 to 255) on classic Arduino; up to 16-bit on ESP32 and Pico
- Arduino
- analogWrite(pin, 0 to 255) on ~ pins
- ESP32
- ledcAttach(pin, freq, resolution), ledcWrite(pin, duty)
- Pico (MicroPython)
- PWM(Pin(n)), freq(), duty_u16(0 to 65535)
- Servo signal
- 50 Hz, 1 to 2 ms pulse (not a duty cycle you set directly)
How PWM works
A digital pin can only be fully on or fully off. PWM turns it on and off thousands of times a second. If it is on 25% of the time, an LED looks a quarter as bright and a motor runs at about a quarter speed, because the load averages the pulses. The eye and a motor's inertia smooth the flicker; a capacitor and resistor can smooth it into a true analog voltage.
PWM on Arduino, ESP32 and Pico
| Board | Pins | Resolution | Frequency | Call |
|---|---|---|---|---|
| Arduino Uno / Nano | 3, 5, 6, 9, 10, 11 | 8-bit | 490 Hz (980 Hz on 5, 6) | analogWrite(pin, 0-255) |
| Arduino Uno R4 | 3, 5, 6, 9, 10, 11 | 8-bit default, up to 12-bit | 490 Hz default | analogWrite(), analogWriteResolution() |
| ESP32 | Almost any GPIO, 16 channels | 1 to 16-bit | 1 Hz to 40 MHz (depends on bits) | ledcAttach(), ledcWrite() |
| Raspberry Pi Pico | All GPIO, 16 slices | 16-bit | 8 Hz to 62 MHz | PWM(Pin(n)).duty_u16() |
| Raspberry Pi 5 | GPIO 12, 13, 18, 19 hardware | Set per request | Any practical | gpiozero PWMLED / PWMOutputDevice |
- Arduino Uno / Nano
- Pins:
- 3, 5, 6, 9, 10, 11
- Resolution:
- 8-bit
- Frequency:
- 490 Hz (980 Hz on 5, 6)
- Call:
- analogWrite(pin, 0-255)
- Arduino Uno R4
- Pins:
- 3, 5, 6, 9, 10, 11
- Resolution:
- 8-bit default, up to 12-bit
- Frequency:
- 490 Hz default
- Call:
- analogWrite(), analogWriteResolution()
- ESP32
- Pins:
- Almost any GPIO, 16 channels
- Resolution:
- 1 to 16-bit
- Frequency:
- 1 Hz to 40 MHz (depends on bits)
- Call:
- ledcAttach(), ledcWrite()
- Raspberry Pi Pico
- Pins:
- All GPIO, 16 slices
- Resolution:
- 16-bit
- Frequency:
- 8 Hz to 62 MHz
- Call:
- PWM(Pin(n)).duty_u16()
- Raspberry Pi 5
- Pins:
- GPIO 12, 13, 18, 19 hardware
- Resolution:
- Set per request
- Frequency:
- Any practical
- Call:
- gpiozero PWMLED / PWMOutputDevice
Code examples
// Arduino Uno: pin 9 is a ~ (PWM) pin
void setup() { pinMode(9, OUTPUT); }
void loop() {
for (int d = 0; d < 256; d++) { analogWrite(9, d); delay(4); }
}
// ESP32 (arduino-esp32 3.x): 5 kHz, 10-bit resolution on GPIO 18
// void setup() { ledcAttach(18, 5000, 10); }
// void loop() { for (int d = 0; d < 1024; d++) { ledcWrite(18, d); delay(2); } }Which PWM frequency should you use?
| Load | Suggested frequency | Why |
|---|---|---|
| LEDs (indicator, strips through MOSFET) | 1 to 20 kHz | Above 1 kHz no visible flicker; higher avoids camera banding |
| DC motors through a driver | Under 1 kHz for L298N; 15 to 25 kHz for MOSFET drivers | Sub-kHz whines audibly; 20 kHz+ is silent and efficient on MOSFET drivers |
| Hobby servos | 50 Hz exactly | The servo reads the pulse width, not the duty |
| Heaters, SSR (slow) | 1 to 10 Hz | Zero-cross SSRs cannot switch fast |
| PWM to analog (DAC) | 10 kHz+ with an RC filter | Easier to filter at high frequency |
- LEDs (indicator, strips through MOSFET)
- Suggested frequency:
- 1 to 20 kHz
- Why:
- Above 1 kHz no visible flicker; higher avoids camera banding
- DC motors through a driver
- Suggested frequency:
- Under 1 kHz for L298N; 15 to 25 kHz for MOSFET drivers
- Why:
- Sub-kHz whines audibly; 20 kHz+ is silent and efficient on MOSFET drivers
- Hobby servos
- Suggested frequency:
- 50 Hz exactly
- Why:
- The servo reads the pulse width, not the duty
- Heaters, SSR (slow)
- Suggested frequency:
- 1 to 10 Hz
- Why:
- Zero-cross SSRs cannot switch fast
- PWM to analog (DAC)
- Suggested frequency:
- 10 kHz+ with an RC filter
- Why:
- Easier to filter at high frequency
Turning PWM into a real analog voltage
Put a resistor and capacitor in series from the PWM pin to ground and take the voltage across the capacitor. With 4.7 kΩ and 10 µF the filter smooths a 1 kHz signal to a steady average with small ripple. For a clean DAC output use a dedicated DAC (the ESP32 has two, the MCP4725 works over I2C).
PWM vs servo control
Servos use a 50 Hz signal, but the information is the pulse length (1 to 2 ms), not the duty cycle. Use the Servo library or a PCA9685 rather than analogWrite. See servo motors.
Try it: PWM duty cycle calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Using analogWrite on a non-PWM Arduino pin, which just switches it on or off.
- Driving motors at 490 Hz through a MOSFET and getting an audible whine; raise the frequency.
- Calling analogWrite for a servo instead of the Servo library.
- Expecting PWM to produce a true analog voltage without a filter.
- Using an SSR with a kHz PWM; zero-cross SSRs cannot keep up.
Frequently asked questions
What does PWM stand for?
Pulse-width modulation: varying the width (on time) of fixed-frequency pulses to control the average power delivered to a load.
What is duty cycle?
The fraction of each PWM period that the signal is on. 75% duty cycle means on three-quarters of the time, so an LED looks about three-quarters bright.
Which Arduino pins support PWM?
On the Uno and Nano: pins 3, 5, 6, 9, 10 and 11, marked with a tilde (~). The Mega has 15 PWM pins.
Can I change the PWM frequency on an Arduino?
Yes, by changing timer prescalers, but it affects millis() on some timers. The ESP32 and Pico let you set frequency directly in code.
Is PWM the same as analog output?
No. PWM is a digital on-off signal whose average equals an analog level. It works for LEDs, motors and heaters, but needs an RC filter or a DAC to make a steady voltage.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 8 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
- Arduino analogWrite() reference (Arduino)
- ESP32 LED Control (LEDC) documentation (Espressif Systems)
- RP2040 datasheet, PWM chapter (Raspberry Pi Ltd)
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.


