Arduino PWM: How analogWrite Really Works
analogWrite() does not output analog voltage. It outputs a square wave at ~490 Hz whose duty cycle the share of time high sets the average energy. Motors see speed, LEDs see brightness, and filters see a controllable DC level.
> At a glance: 7 minute guide · part 3 of 10 in the complete Arduino guide track · includes a worked example and a quick-reference table.
## Duty cycle math
Here is the working theory in one pass. A value of 0–255 maps to 0–100 % duty. analogWrite(pin, 128) yields ~50 % duty, so a 5 V-driven LED averages about 2. 5 V and a motor runs at roughly half speed. Average voltage = supply × duty.
| a | n | a | l | o | g | W | r | i | t | e | | v | a | l | u | e | | | | | |
| — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — |
| D | u | t | y | | c | y | c | l | e | | | | | | | | | | | | |
| A | v | e | r | a | g | e | | v | o | l | t | a | g | e | | a | t | | 5 | | V |
| 0 | 0 % | 0 V | | | | | | | | | | | | | | | | | | | |
| 64 | 25 % | 1.25 V | | | | | | | | | | | | | | | | | | | |
| 128 | 50 % | 2.5 V | | | | | | | | | | | | | | | | | | | |
| 192 | 75 % | 3.75 V | | | | | | | | | | | | | | | | | | | |
| 255 | 100 % | 5 V (constant high) | | | | | | | | | | | | | | | | | | | |
## What PWM can and cannot do
It works beautifully for anything with inertia or persistence. Motors, heaters, LED brightness, servo signalling (servos use their own 50 Hz protocol via the library). It cannot directly power an analog input of another board low-pass filter it first (a resistor and capacitor roll off the ripple).
## Frequency and noise
Pins 5 and 6 run at ~980 Hz on an Uno; the others at ~490 Hz. Audible whine in a motor or flicker in a camera frame are frequency artifacts. Timer libraries can shift PWM frequency when the default annoys ears or sensors.
## How to apply this in your build
Work through the sequence below each step assumes the previous one passed. For numbers that need calculating, the linked tools at the end of this guide do the arithmetic instantly.
1. Pick a PWM-capable pin (3,5,6,9,10,11 on Uno)
2. Call analogWrite(pin, 0–255)
3. For true analog voltage, add an RC low-pass filter
4. Check the load tolerates ~490 Hz switching
### Worked example
Dimming an LED: analogWrite(9, 51) ≈ 20 % duty ≈ 1 V average. The eye integrates the pulses into steady dimness no filter needed. Run the numbers yourself with the LED Resistor Calculator and the result should agree to within rounding.
> Practical note from the bench. Procirel tip: a 220 Ω resistor plus 10 µF capacitor turns any PWM pin into a usable 0–5 V analog source for testing op-amp circuits.
## Pitfalls that cost real hardware
– Expecting analogWrite to drive an analog input directly without filtering
– Using PWM pins 0/1 (they are not PWM plan around serial)
– Overlooking audible whine from 490 Hz in gearmotors
## Key takeaways
– Duty cycle math the foundation of this guide; revisit it if any measurement here surprises you.
– What PWM can and cannot do the foundation of this guide. Revisit it if any measurement here surprises you.
– Frequency and noise the foundation of this guide; revisit it if any measurement here surprises you.
## Who this guide is for
Beginners get a single focused topic instead of a whole textbook chapter. It works as an early stop in the complete Arduino guide path. Intermediate readers use it as a reference the table, the worked example and the mistake list answer the questions that come up mid-build. If you teach, the structure (theory, application, example, failure modes) maps cleanly onto a lab session.
## What you need before starting
Nothing exotic: the parts or tools named in the guide, a multimeter. The LED Resistor Calculator open in a tab. Pick a PWM-capable pin (3,5,6,9,10,11 on Uno) before you begin the guide assumes it and keep the quick-reference table above within sight while you work through the steps.
### Quick reference card
| Aspect | Where to find it in this guide |
| — | — |
| Core theory | Duty cycle math |
| Application steps | How to apply this in your build |
| Worked numbers | Worked example |
| Failure modes | Pitfalls that cost real hardware |
## How this fits the complete Arduino guide track
This guide is one stop in the structured learning path. Start from the [complete Arduino guide](/tutorial/arduino-complete-guide) pillar page for the full map, or continue with [GPIO pin capabilities](/tutorial/arduino-gpio-pinout-guide) and [reading analog inputs](/tutorial/arduino-analog-read-adc). For the arithmetic, open the [LED Resistor Calculator](/tools/led-resistor).
## Frequently asked questions
Why is my “analog” output 5 V on the meter?
Cheap meters average slowly or peak-hold; a scope shows the true square wave. Filter for real DC.
How do I change PWM frequency?
Adjust timer prescalers or use a library we cover the trade-offs with the timers tutorial series.
Is there a calculator for this?
Yes the [LED Resistor Calculator](/tools/led-resistor) tool runs the formulas from this guide instantly, client-side, with no signup.
## Where to go next
– The complete arduino & microcontrollers guide: [Arduino & Microcontrollers complete guide](/tutorial/arduino-complete-guide)
– Read next: [what is an embedded system? microcontrollers in everything](/tutorial/what-is-embedded-system)
– Also in this track: [esp32 vs stm32: choosing your next microcontroller](/tutorial/esp32-vs-stm32-comparison)
– Continue with: [arduino ide 2 setup: from download to first upload](/tutorial/arduino-ide-setup-guide)
– Calculate as you go: [LED series resistor finder](/tools/led-resistor) · [battery runtime estimator](/tools/battery-life) · [555 frequency calculator](/tools/timer-555-astable)
– Bookmark this page against the day a measurement surprises you. Most readers return to the table and the mistake list first, and that is the correct order.
## From our lab notebook
Uninitialised variables and pins left floating. Set every pinMode and initial state in setup.
Anything with motors, servos or many LEDs needs external supply with common ground. USB is for logic only.
## How to revisit this guide
Second readings work best with a purpose. Pick one section from Duty cycle math,What PWM can and cannot do,Frequency and noise and rebuild only that part at the bench, predicting each value before measuring. Prediction errors mark exactly which concept needs the next pass, and the linked arduino calculators resolve any arithmetic doubt in seconds. Keep the marked sections in your notebook: after a month of builds, that list becomes your personal Arduino syllabus.
Procirel