Arduino PWM pins generate pulse width modulation signals that let you control analog behavior in digital projects. These pins vary voltage timing instead of delivering true analog output, making them ideal for LED dimming, motor speed, and servo control.
Understanding which pins support PWM and how to use them helps you design more responsive and power-efficient projects on Uno, Nano, Mega, and compatible boards.
| Board | PWM Pins | Resolution | Max Frequency Approx. |
|---|---|---|---|
| Arduino Uno | 3, 5, 6, 9, 10, 11 | 8-bit (0–255) | ~490 Hz (channels 5,6), ~980 Hz (channels 9,10), ~3.9 kHz (channels 3,11) |
| Arduino Nano | 3, 5, 6, 9, 10, 11 | 8-bit (0–255) | Same as Uno |
| Arduino Mega | 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13 | 8-bit (0–255) | Varied; 16-bit timers give stable frequencies around 976 Hz on many channels |
| Arduino Due | 2–13 | 12-bit (0–4095) | Up to several kHz with higher resolution |
Hardware PWM Capabilities by Board
Each Arduino board uses different timers and pins, which shape how many PWM channels and what frequency ranges you can access. Timers are shared resources, so using one channel affects others on the same timer.
On Uno and Nano, Timer0 serves system functions, while Timers 1 and 2 drive other pins. On Mega, more timers expand flexible PWM options, but you must avoid conflicts when adding libraries or custom code.
Choosing the right board and pin ensures enough resolution for smooth motor control and enough frequency for quiet actuator operation without audible switching noise.
Setting PWM Frequency and Resolution
Frequency determines how fast the signal toggles, affecting noise and smoothness, while resolution defines step granularity, usually set by the timer bit depth. By default, Arduino uses 8-bit resolution, giving 256 steps.
You can adjust registers to trade speed for precision, shifting to 10-bit or 12-bit modes on capable hardware. Higher resolution reduces step size, which is valuable for precise motor control or smooth LED fading.
Changing frequency can reduce audible artifacts in motors and servos, but it may affect libraries relying on millis or delay functions, so test real-world behavior after tuning.
Analog-Like Control with ledc
On ESP32, ledc channels replace basic Arduino analogWrite and let you assign independent frequency and resolution per channel. This design prevents timer clashes and supports sophisticated dimming profiles.
You can configure ledc once and then reuse handles to fade multiple LEDs or drive several motors without recalculating duty cycles each loop. This modular approach scales well to complex projects.
Mapping your desired brightness or speed to a duty cycle requires normalization formulas that consider bit depth and target range, ensuring linear perceived changes.
Advanced Techniques and Project Tips
Phase-correct PWM modes reduce harmonic noise by symmetrically toggling edges, at the cost of lower maximum frequency. This mode suits audio projects where quality matters more than top speed.
Using interrupts or timer callbacks lets you update outputs in sync with other tasks, avoiding jitter in motor control or sensor sampling. Keep ISRs short and delegate work to the main loop.
Monitoring actual output with an oscilloscope validates timing assumptions, especially when libraries abstract low-level details and frequency shifts are not obvious in code.
Practical Recommendations and Takeaways
- Always verify PWM pin mapping on your specific board before wiring LEDs or motors.
- Use higher resolution only when precision matters, to keep frequency within audible and usable ranges.
- Test motor behavior at different frequencies to find a balance between smoothness and noise.
- Reserve ledc channels on ESP32 for complex projects needing independent control and flexible duty cycles.
- Document any timer changes so future sketches or libraries do not unexpectedly interfere with your setup.
FAQ
Reader questions
Why are some of my PWM pins not responding to analogWrite changes?
Check whether the pin is a true PWM pin on your board, verify that the pin is not overloaded with conflicting libraries, and ensure analogWrite values are within 0–255 for 8-bit resolution on standard Uno/Nano.
Can I use PWM on non-PWM digital pins by software modulation?
Yes, you can toggle a normal pin with delayMicroseconds to simulate PWM, but the frequency will be lower, and timing jitter may appear, so reserve this method for situations where hardware PWM channels are fully used.
How do timer conflicts happen when using multiple PWM channels?
Channels sharing a timer may reset the timer counter together, causing linked frequency changes; modifying frequency or duty on one channel affects others, so consult the chip datasheet and test combinations in your sketch.
Is it safe to change PWM frequency inside a loop without extra safeguards?
Not safe, because runtime register updates can interrupt timing-sensitive operations; apply changes once in setup or protect updates with interrupts or flags to prevent glitches in motors or audio.