# Pulse-Width Modulation (PWM)

> Turning a pin on and off very fast. It dims a light or slows a motor.

**Field:** Software Development  
**Category:** Embedded & IoT  
**Also known as:** PWM, PWM Pin, analogWrite, Duty Cycle

## Think of it like

It is like flicking a light on and off so fast it looks half bright.

## Definition

Pulse-width modulation fakes a level between on and off by switching a pin very fast. The pin turns on and off hundreds of times a second. The share of time it is on is called the duty cycle. On a quarter of the time, a light looks dim. On three quarters of the time, it looks bright, and a motor spins faster.

## Example

On an Arduino Uno, analogWrite takes 0 to 255. A value of 64 keeps an LED on about a quarter of the time, so it glows dim.

## Example code

```cpp
analogWrite(9, 64);  // pin 9 on about a quarter of the time
```

One line sets a PWM pin to about a quarter on, so the light is dim.

## Why it matters

Digital pins can only be on or off. PWM is how they dim lights, mix colours and set motor speed.

## Common mistake

Using a pin that cannot do PWM. On an Uno only pins 3, 5, 6, 9, 10 and 11 can, and the others just switch on or off.

## Three principles

- **Fast switching.** On and off many times a second.
- **Duty cycle.** The share of time it is on.
- **Looks smooth.** Eyes and motors see the average.

## Related terms

- [General-Purpose Input/Output (GPIO)](https://learn.benibix.com/term/development/gpio)
- [Analog-to-Digital Converter (ADC)](https://learn.benibix.com/term/development/analog-to-digital-converter)
- [Arduino](https://learn.benibix.com/term/development/arduino)
- [Microcontroller (MCU)](https://learn.benibix.com/term/development/microcontroller)

![Four rows, one per kind of pin signal. GPIO: a line that is either high or low, on or off. ADC: a knob turns a smooth voltage into a number from 0 to 1023. PWM: two square waves, one on a quarter of the time for a dim light and one on three quarters of the time for a bright one. Interrupt, lit up: a button press makes the chip stop its loop at once, run a short handler, then go back.](https://learn.benibix.com/diagrams/dev4-pin-signals.svg)

---

Source: https://learn.benibix.com/term/development/pulse-width-modulation
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
