
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.
- Pick a PWM-capable pin (3,5,6,9,10,11 on Uno)
- Call analogWrite(pin, 0-255)
- For true analog voltage, add an RC low-pass filter
- 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 complete guide for the full map, or continue with GPIO pin capabilities and reading analog inputs. For the arithmetic, open the LED Resistor Calculator.
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 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
- Read next: what is an embedded system? microcontrollers in everything
- Also in this track: esp32 vs stm32: choosing your next microcontroller
- Continue with: arduino ide 2 setup: from download to first upload
- Calculate as you go: LED series resistor finder · battery runtime estimator · 555 frequency calculator
- 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.
Extended Application Notes
This section expands the practical application of arduino pwm: how analogwrite really works beyond the worked example, into the situations builders actually meet. Component substitution: when the exact specified part is unavailable, the substitution logic follows the governing parameter of this design, not the nominal value, and the verification step after any substitution is to re-measure the one quantity this guide identified as critical. Batch variation: components vary, and the design margins recommended in the sections above absorb that variation; if a second build behaves differently, the difference itself is diagnostic and points to the tolerance that dominated. Environmental limits: temperature, supply variation and ageing each push a real circuit away from its bench behaviour, and the recommended practice is to test the extremes deliberately rather than discover them in the field. These notes exist because the bench taught them, repeatedly, and each one was once a real troubleshooting session that ended in understanding.
Failure Analysis in Depth
The mistakes section above lists the traps; this section explains why each trap exists and how to recognize it early. 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. Each of these failures has a signature that appears in measurement before it appears in smoke: a reading that drifts, a waveform that differs from the prediction, a temperature that climbs faster than the calculation. The discipline this guide teaches is to measure at the first sign, not at the last, and the sections above give the specific instrument and setting for each check. Failure analysis is not pessimism; it is the fastest curriculum in electronics, because a fault understood once is a fault prevented forever.
Pre-Build Checklist
Before powering any build of this design, run the list: every component value verified against the specification above, the critical measurement points identified and accessible, the instrument modes and ranges chosen in advance, the expected values written down beside the bench, and the power source current-limited for first application. The checklist takes two minutes and replaces the most expensive class of beginner error, which is not ignorance but confidence outrunning verification. Builders who adopt the checklist across the guides in this track report first-apply success rates that feel like cheating, but it is not cheating, it is engineering.
What Comes Next
Having worked through this guide, the natural next steps are the adjacent guides in the track index above, each of which assumes exactly the vocabulary this page built. The calculators linked in the tools section verify every number in seconds, and the complete guide at the head of this track maps the entire curriculum. Read once, build once, measure always: that is the method this site teaches and the method every section above followed before publication.
Theory in Practice, Extended
The theory section of arduino pwm: how analogwrite really works deserves one more pass with the bench in mind, because knowing a relationship and applying it under constraint are different skills. In application, the relationship is never isolated: it interacts with tolerances, with temperature, with the behaviour of adjacent stages, and with the measurement itself. The extended practice is to take the governing formula from the sections above and stress it, deliberately. Push the input to the edge of its specified range and watch the output follow the prediction, then push past it and watch the prediction break, because the edge of the specification is exactly where the formula stops being the whole story. That boundary, found on the bench rather than in the datasheet, is the real knowledge this guide offers beyond the mathematics.
Component Sourcing and Substitution Notes
Real builds meet real supply chains, and this section addresses the practical reality. The specified components in this guide were chosen for the reasons stated in the design sections, but equivalent parts from reputable manufacturers almost always serve, provided the governing parameters match, not merely the nominal ones. The substitution checklist: match the parameter this guide identified as critical, verify the package and pinout against the physical part before layout, check the datasheet revision for silent changes, and re-run the verification measurement after installation. Avoid unbranded surplus and marketplace components for anything this guide treats as safety-relevant; the failure mode of a counterfeit is not degradation, it is unpredictability, and unpredictability defeats every other design decision in the chain.
Instrumentation for This Design
Every measurement recommended in this guide maps to a specific instrument configuration, and this section consolidates them. Voltage checks: DC range selected before probing, leads verified against a known source, meter burden considered when the node is high impedance. Current checks: circuit broken at the defined point, meter inserted with the correct range and fuse status confirmed first. Waveform checks: probe compensated against the reference before any amplitude claim, ground lead kept short, bandwidth sufficient for the edge rather than the repetition rate. The instrumentation discipline matters more than the instrument class, and a modest instrument used correctly outperforms an expensive one used casually, a claim this site demonstrates throughout its measurement guides.
Documentation Template for This Build
Close the loop the way professional builds do: record the design values from this guide, the as-built values including every substitution, the measured results beside the predicted ones, and the deviation notes that explain every gap. The template is short, a single page, and it converts a successful build into a reference that survives component changes, firmware updates and the passage of months. Every guide on this site was built and documented exactly this way before publication, and the discipline is offered here as part of the curriculum rather than an afterthought. A build that is documented is twice built, once in copper and once in confidence.
One practical note: the classic Arduino PWM frequency is ~490Hz (980Hz on pins 5 and 6), which is audible in motors and dimmable LEDs as a whine or flicker. Moving to a higher PWM frequency is a two-register change and turns both annoyances off.
Last updated 23 August 2026
