Arduino PWM pins generate pulse width modulation signals that let you control analog-like behavior such as LED brightness, motor speed, and servo positioning. By varying the duty cycle, you can smoothly adjust power delivery without relying on manual resistors or external controllers.
Understanding how PWM works on different Arduino boards helps you choose the right hardware and avoid common issues like flicker, noise, or voltage drops. The table below highlights the PWM capabilities of popular boards.
| Board | PWM Pins | Resolution (bits) | Max Frequency (approx.) |
|---|---|---|---|
| Arduino Uno | 3, 5, 6, 9, 10, 11 | 8-bit | 490 Hz (some 980 Hz) |
| Arduino Nano | 3, 5, 6, 9, 10, 11 | 8-bit | 490 Hz (some 980 Hz) |
| Arduino Mega 2560 | 2–13, 44–46 | 8-bit | 490 Hz on most, 976 Hz on 44–46 |
| Arduino Due | 2–13, DAC0, DAC1 | frequency varies by timer||
| Arduino Leonardo | 3, 5, 6, 9, 10, 11 | 8-bit | 490 Hz (some 980 Hz) |
Hardware PWM Timers and How They Work
Each Arduino board uses dedicated hardware timers to generate PWM signals. Timer prescalers, compare match registers, and output compare units determine frequency and resolution. Changing timer settings can unlock higher frequencies or finer granularity, but may conflict with libraries or delay functions that rely on default timer behavior.
Timer Selection and Trade-offs
Timer0 controls millis and micros on Uno and Nano, so modifying it affects time-sensitive code. Timer1 and Timer2 offer independent channels for additional PWM channels and higher frequencies. On the Mega, Timer3–Timer5 provide extra flexibility without disrupting common library-dependent timers.
Advanced PWM Techniques and Signal Quality
At higher frequencies, you can reduce visible flicker in LEDs and minimize audible noise in motors. Switching to phase-correct PWM modes changes symmetry and affects duty range, so you must update TCCR register bits rather than relying on analogWrite. Adding low-pass filters converts PWM into clean analog voltages for sensors and actuators.
Filtering and Protection
RC filters smooth PWM output, while zener diodes and transistors protect downstream circuits from voltage spikes. Always check current limits on Arduino pins and use transistors or motor drivers for high-power loads to avoid damaging the microcontroller.
Frequency, Resolution, and Stability Considerations
Default 8-bit resolution gives 256 steps, but some libraries expand resolution at the cost of maximum frequency. Changing prescalers adjusts frequency, trading off between granularity and switching losses. On 16 MHz boards, phase-correct modes near 31250 Hz balance stability and smoothness without excessive jitter.
Best Practices and Recommendations
- Use motor drivers or MOSFETs to handle currents above a few hundred milliamps.
- Keep PWM frequency above 200 Hz for lighting to reduce visible flicker.
- Reserve Timer0 for time-critical tasks unless you understand the side effects.
- Test signal integrity with an oscilloscope when precision control is required.
- Match PWM resolution and frequency to your application’s smoothness and response needs.
FAQ
Reader questions
Which PWM pins are safe for motor control without a driver?
Use external motor drivers like TB6612FNG or L298N; never connect motors directly to PWM pins due to current and voltage spikes that can damage the board.
Can I get more than 8-bit resolution on a Uno?
Yes, by tweaking timer registers you can achieve 10-bit or 12-bit resolution, though maximum frequency will decrease and Timer0 changes may affect millis and Servo stability.
Why does my LED flicker when using PWM at low frequencies?
Low frequencies fall below the persistence-of-vision threshold; raise the frequency to at least a few hundred hertz and verify the duty cycle range matches your expected brightness levels.
Will changing PWM settings interfere with Servo or Tone libraries?
Yes, Servo and Tone rely on specific timer channels; if you modify those timers, move servos to hardware-compatible pins or use alternative libraries that support flexible timer assignments.