December 4, 2026

PWM Explained: Duty Cycle, Frequency, and Why Half Power Doesn’t Look Half as Bright

An oscilloscope showing a square wave with narrow high pulses

An Arduino Uno has no way to output 2.5 volts. Its pins are either 0 V or 5 V. Yet analogWrite(9, 128) dims an LED to what looks like partway, and slows a motor to roughly half speed. The trick is pulse width modulation: switching the pin fully on and fully off hundreds of times a second and letting whatever is attached average it out. Two numbers control it, the duty cycle and the frequency, and a third effect, the way eyes perceive light, explains why a value of 128 looks much brighter than half. The figures below come from the Arduino documentation, a time-step simulation of a PWM signal through a filter, and the standard formula for perceived lightness.

Video: Simply Electronics on YouTube

Duty cycle: the share of time spent on

The definition

A PWM signal repeats a fixed period. Within each period, the pin is high for some fraction of the time and low for the rest. That fraction is the duty cycle. At 25 percent, the pin is high a quarter of the time; at 100 percent, it never goes low.

In Arduino terms

The Arduino reference describes analogWrite() as writing an analog value (PWM wave) to a pin, which can light an LED at varying brightness or drive a motor at various speeds. Its value parameter is the duty cycle, between 0 (always off) and 255 (always on). A value of 128 is about 50 percent.

The average

The average voltage of a PWM signal is the supply voltage times the duty cycle. On a 5 V pin, 50 percent averages 2.5 V. With 256 possible values, each step is 5 V / 255, about 19.6 mV; on a 3.3 V board, about 12.9 mV. That is the finest resolution an 8-bit PWM can reach.

LED

Frequency: how fast it repeats

The Uno’s defaults

The Arduino reference lists the PWM frequency for each board. For the Uno, Nano and Mini, PWM pins 3, 5, 6, 9, 10 and 11 run at 490 Hz (pins 5 and 6: 980 Hz). Other boards differ; the same table lists 732 Hz for MKR boards and 1,000 Hz for the Due.

Where the numbers come from

Arduino’s tutorial “Secrets of Arduino PWM” shows the arithmetic. The Uno’s 16 MHz clock is divided by a prescaler of 64 and then by 256 counter steps, giving 16 MHz / 64 / 256 = 976.5625 Hz in “fast PWM” mode, the “980 Hz” in the table. In the “phase-correct” mode used on the other pins, the counter counts up and then back down, which halves the rate to 16 MHz / 64 / 255 / 2, about 490.2 Hz. The tutorial also notes that analogWrite() provides no control over frequency; changing it means writing to the timer registers directly.

Why it matters

For an LED, anything above the eye’s flicker threshold looks steady, and both default frequencies are well above that for direct viewing. For a motor, frequency decides whether the windings whine audibly. For a filter that turns PWM into a real analog voltage, frequency decides how smooth the result is, which the next section measures.

Turning PWM into a real voltage

An RC filter

A resistor and capacitor between the pin and the load average the pulses into a steady-ish voltage. A simulation stepped a 5 V, 50 percent PWM signal through a 10 kΩ resistor into a 1 µF capacitor, a time constant of 10 ms, and measured the leftover ripple once it settled:

PWM frequency Average Ripple (peak to peak)
50 Hz 2.50 V 2,312 mV
490 Hz 2.50 V 255 mV
980 Hz 2.50 V 128 mV
20 kHz 2.50 V 6.3 mV

What the table shows

The average was 2.50 V every time; only the ripple changed. At 50 Hz the filter barely smoothed anything. At the Uno’s 490 Hz, a quarter of a volt of ripple remained, more than ten times the 19.6 mV step size, so the extra resolution was buried in noise. At 20 kHz the ripple dropped below one step. Doubling the frequency halved the ripple at these settings.

The trade-off

A bigger capacitor smooths more but responds slower. This filter takes about 46 ms, 4.6 time constants, to settle within 1 percent of a new value. Fine for setting a reference voltage, too slow for audio. Raising the PWM frequency is the better way to get both smooth and fast.

LED background

LEDs: why 128 looks almost full brightness

Linear light, non-linear eyes

An LED driven by PWM emits light in proportion to the duty cycle: half the duty, half the photons. People do not perceive it that way. Human lightness perception is roughly a cube-root curve: small amounts of light look relatively bright, and doubling already-bright light looks like a small change.

The CIE lightness formula

The standard description of perceived lightness, L* from the CIE, is a straight line near black and a cube-root curve above it. A write-up of the formula by photographer and engineer Bill Claff gives the inverse, from desired lightness to physical luminance, and notes that Y = .184 for L* = 50: the origin of the 18 percent gray standard. Applied to a PWM LED:

Perceived brightness Duty cycle needed analogWrite value
10% 1.1% 3
25% 4.4% 11
50% 18.4% 47
75% 48.3% 123
100% 100% 255

An analogWrite of 128 lands near 75 percent perceived brightness. “Half as bright” is around 47.

What this means for fades

A fade that steps the value evenly from 0 to 255 looks like it rushes through the dim end and then crawls with little visible change at the top. A lookup table built from the formula above, mapping even steps of perceived brightness to duty values, makes a fade look even. The same correction is used in display backlight drivers; the Linux kernel’s PWM backlight driver includes a CIE 1931 lightness function for the purpose.

The cost at the dim end

The table also exposes 8-bit PWM’s limit. Ten percent perceived brightness needs a value of 3, and the next steps are 4 and 5, so very low brightness levels jump visibly. Boards and drivers with 10-bit, 12-bit or 16-bit PWM have many more steps down there, which is why smooth dimming hardware uses higher resolution.

Frequency against resolution

One clock, two demands

A hardware PWM is a counter running from a fixed clock. Each period, it counts through all its steps, so more steps of resolution means a longer period, which means a lower frequency. Using the Uno’s 16 MHz clock with no prescaler, the formula from Arduino’s tutorial (clock divided by the number of counter steps) gives:

Resolution Steps Fastest PWM frequency Step size at 5 V
8-bit 256 62,500 Hz 19.6 mV
10-bit 1,024 15,625 Hz 4.9 mV
12-bit 4,096 3,906 Hz 1.2 mV
16-bit 65,536 244 Hz 0.08 mV

What to pick

A 16-bit PWM has wonderfully fine steps but runs at 244 Hz from this clock, slow enough to see flicker in peripheral vision or a camera, and slow enough to need a big filter for a smooth voltage. An 8-bit PWM at 62.5 kHz is silent and easy to filter but coarse at the dim end. Microcontrollers with faster clocks push the whole table up, which is one reason newer boards dim LEDs more smoothly. For most hobby LED work, 10 or 12 bits at a few kilohertz is a comfortable middle.

Semiconductor

Motors and other loads

Speed, not voltage

For a DC motor, PWM works because the motor’s inductance and inertia average the pulses. At 50 percent duty, the motor sees full voltage half the time and coasts the other half, which gives roughly half speed under light load. It also keeps more torque at low speed than reducing the voltage with a resistor would, because each pulse is at full voltage.

Switching it safely

An Arduino pin can’t supply a motor’s current. A transistor or MOSFET does the switching, with a diode across the motor to absorb the voltage spike each time the current is cut. The earlier post on using a MOSFET as a switch covers choosing the part, and the post on decoupling capacitors explains why fast switching of large currents needs a solid supply.

The whine

At 490 Hz or 980 Hz, many small motors hum audibly, because the windings vibrate at the PWM frequency. Moving the frequency above about 20 kHz, beyond most people’s hearing, removes the hum. On the Uno that means changing timer registers, as the Arduino PWM tutorial describes, and it adds switching losses in the transistor.

Sources

  • analogWrite(), Arduino Documentation: https://docs.arduino.cc/language-reference/en/functions/analog-io/analogWrite/
  • analogWrite() reference with board PWM frequency table, Arduino: https://arduino.cc/en/Reference/AnalogWrite
  • Secrets of Arduino PWM, Arduino Documentation: https://docs.arduino.cc/tutorials/generic/secrets-of-arduino-pwm/
  • Psychometric Lightness and Gamma, Bill Claff (photonstophotos.net): https://photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm

719 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *