// DIGITAL & ARDUINO · 3 MIN READ

PWM Explained: How analogWrite Dims an LED on Arduino (Duty Cycle)

What PWM is, how duty cycle sets the average voltage, and how Arduino analogWrite (0–255) dims LEDs and controls motors. PWM pins, frequency, simulator.

ON THIS PAGE
  1. Free PWM simulator
  2. Duty cycle in one picture
  3. Why doesn't the LED flicker?
  4. Arduino PWM code
  5. Which pins can do PWM?
  6. PWM for motors
  7. Is PWM real analog?
  8. Frequently asked questions

An Arduino pin can only be fully ON (5 V) or fully OFF (0 V). So how does analogWrite() make an LED glow at half brightness, or a motor spin slowly? The trick is called PWM — pulse width modulation: switching the pin on and off so fast that your eye (or the motor) only feels the average.

Free PWM simulator

Change the duty cycle and the frequency. You see the square wave, the average voltage and the LED dimming:

⚡ LOADING THE CALCULATOR…

Free, no sign-up. Prefer a bigger screen? Open the PWM dimmer calculator in the Lab →

Duty cycle in one picture

Imagine a light switch flipped on and off 500 times a second:

Duty cycleON timeAverage on a 5 V pinanalogWrite value
0 %never0 V0
10 %1 part in 100.5 V≈ 25
25 %a quarter1.25 V≈ 64
50 %half2.5 V≈ 127
75 %three quarters3.75 V≈ 191
100 %always5 V255

Why doesn't the LED flicker?

Above about 50–100 flashes a second, your eye can't follow them and blends them into a steady, dimmer light. The Arduino Uno's PWM runs at about 490 Hz (pins 5 and 6 at about 980 Hz) — far too fast to see.

Arduino PWM code

const int LED = 9;            // a PWM pin (marked ~)

void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
  for (int v = 0; v <= 255; v++) {   // fade up
    analogWrite(LED, v);
    delay(5);
  }
  for (int v = 255; v >= 0; v--) {   // fade down
    analogWrite(LED, v);
    delay(5);
  }
}

Use a 220 Ω resistor in series with the LED, as always (see the LED resistor guide).

Which pins can do PWM?

BoardPWM pinsNotes
Arduino Uno / Nano3, 5, 6, 9, 10, 11 (marked ~)8-bit: analogWrite 0–255
Arduino Mega2–13, 44–468-bit
ESP32almost any output pinledcWrite() / analogWrite() in core 3.x, adjustable resolution and frequency
Raspberry Pi Picoevery GPIO16 PWM channels

PWM for motors

A motor responds to the average too, so PWM controls its speed. But never drive a motor straight from a pin — a pin gives only about 20 mA. Use a transistor, MOSFET or a motor driver (like the L298N or TB6612) and send the PWM to its input. The motor's inertia smooths the pulses.

Is PWM real analog?

No — the pin is still only 0 or 5 V; the output just behaves like an analog level for slow things (eyes, motors, heaters). If you need a real steady voltage, add an RC low-pass filter (see RC time constant) or use a DAC.

Frequently asked questions

What does PWM stand for?

Pulse width modulation: changing the width (ON time) of fast pulses to control the average power.

What is duty cycle?

The percentage of each cycle that the signal is ON. 50 % duty means ON half the time and OFF half the time.

What is the PWM frequency of Arduino Uno?

About 490 Hz on pins 3, 9, 10 and 11, and about 980 Hz on pins 5 and 6.

What is the range of analogWrite?

0 to 255 on Arduino Uno: 0 is always off, 255 is always on, 127 is about 50 % duty.

Can I use PWM on any Arduino pin?

On the Uno, only pins 3, 5, 6, 9, 10 and 11, marked with a ~ on the board.

Md Kaif · @iam.yourprofessor

Makes 30-second electronics lessons for total beginners — 231+ lessons, free video courses and interactive calculators on this site. Every guide is checked against real formulas and datasheets.

// WATCH · 30 SECONDS EACH

Watch it explained in 30 seconds

All lessons →
// FREE VIDEO COURSE

Go deeper: free 3-minute video lessons

All free courses →
// KEEP LEARNING

More free guides

All guides →