Learn Arduino Tutorials Open the 3D lab

Beginner · 6 min read

PWM explained — Arduino analogWrite, duty cycle and the ~ pins

An Arduino pin can only be fully on or fully off — yet it can dim an LED smoothly and run a motor at half speed. The trick is switching faster than your eye can follow. Here is how it works.

An Arduino UNO mixing colours on an RGB LED with three PWM pins
Build it yourself in 3DFree, in your browser — no board, no wires, nothing to buy.Open the 3D lab →

The short answer

PWM (pulse-width modulation) switches a pin on and off very fast — about 490 times a second on most UNO pins. The share of time it is on is called the duty cycle. An LED that is on 25 % of the time looks about a quarter bright; a motor gets a quarter of the push.

On Arduino you use it with analogWrite(pin, value), where value goes from 0 (always off) to 255 (always on). It works only on the pins marked ~: 3, 5, 6, 9, 10 and 11 on the UNO.

Duty cycle in one picture

25 %50 %100 % value 64value 128value 255 average ≈ 1.25 V average ≈ 2.5 V 5 V

The pin is always either 5 V or 0 V. What changes is how long each pulse lasts — the width of the pulse, hence the name. The average voltage is:

average = 5 V × value ÷ 255

analogWrite valueDuty cycleAverage voltageAn LED looks…
00 %0 Voff
6425 %≈ 1.25 Vdim
12850 %≈ 2.5 Vmedium
19175 %≈ 3.75 Vbright
255100 %5 Vfull

Why 255? The UNO's PWM is 8-bit: 2⁸ = 256 levels, numbered 0 to 255.

Why it works: your eyes and the motor are slow

At 490 pulses a second, each on-off cycle takes about 2 milliseconds. Your eye cannot see flicker that fast, so it averages the light: a short pulse looks dim, a long pulse looks bright. A motor is even slower — its spinning mass smooths the pushes into a steady speed.

Which pins can do PWM

UNO pinPWM (~)?
3, 5, 6, 9, 10, 11Yes
0, 1, 2, 4, 7, 8, 12, 13No — only fully on or off
A0–A5No

Look at the board: the PWM pins have a little ~ printed next to their number. If you analogWrite() a non-PWM pin, it just turns on for values of 128 and above and off below — no dimming. See the UNO pinout for every pin.

Example 1: dim an LED with a knob

Our Knob project reads a potentiometer and sets the LED's brightness on pin 9 (a ~ pin):

const int KNOB = A0;
const int LED = 9;   // a ~ pin: it can dim

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int reading = analogRead(KNOB);                // 0 … 1023
  int brightness = map(reading, 0, 1023, 0, 255); // 0 … 255
  analogWrite(LED, brightness);
  Serial.print("knob ");
  Serial.print(reading);
  Serial.print("  ->  LED ");
  Serial.println(brightness);
  delay(100);
}

analogRead() gives 0–1023 but analogWrite() wants 0–255, so map() converts between them. The RGB LED project uses three PWM pins (9, 10, 11) at once to mix any colour.

Turn the knob: the brightness value goes from 0 to 255 and the LED follows
Turn the knob: the brightness value goes from 0 to 255 and the LED follows · open it full screen

Example 2: a motor's speed

A pin cannot power a motor directly — it needs hundreds of milliamps. In our Motor project a TIP120 transistor does the heavy work, and PWM on pin 6 switches it on and off quickly:

for (int speed = 0; speed <= 255; speed += 15) {
  analogWrite(MOTOR, speed);
  Serial.print("speed ");
  Serial.println(speed);
  delay(150);
}

The fan speeds up step by step. In our 3D lab the small motor draws about 0.5 A at full speed, and its speed follows the average current — so analogWrite(6, 128) gives roughly half speed. Read DC motor with a transistor for the wiring.

Common PWM mistakes

  • Using a pin without ~. The LED is just on or off. Move it to 3, 5, 6, 9, 10 or 11.
  • Values over 255. analogWrite(9, 1023) does not mean "full" — use map() or divide by 4.
  • Servos and tone. The Servo library and tone() use the chip's timers too, so PWM on some pins may stop working while they run (with Servo, pins 9 and 10).

Check yourself

  1. What does analogWrite(9, 128) do?

  2. Which of these UNO pins can do PWM?

  3. Why does a fast-blinking LED look dim instead of flickering?

Questions people ask

Is analogWrite a real analog output?

No. The UNO has no true analog output: analogWrite() makes a fast PWM square wave. For LEDs and motors that works like a lower voltage; if you need a smooth voltage, add a resistor and capacitor filter.

What frequency is Arduino PWM?

On the UNO, about 490 Hz on pins 3, 9, 10 and 11, and about 980 Hz on pins 5 and 6.

Why does my LED not dim with analogWrite?

It is probably on a pin without the ~ mark. Move it to pin 3, 5, 6, 9, 10 or 11 — and change the number in the code.

Can I use PWM to control a motor's speed?

Yes, but never directly from the pin. Use a transistor (like the TIP120) or a motor driver, with a diode across the motor, and send PWM to the transistor's base through a resistor.

Build it yourself in 3DFree, in your browser — no board, no wires, nothing to buy.Open the 3D lab →
Next: Arduino Serial Monitor explained — Serial.print, baud rate and input →

Your progress stays on this device — no account, nothing sent anywhere.

Last updated 2026-10-29

Read next