0
0
AutocadHow-ToBeginner · 3 min read

Which Pins Support PWM on Arduino Uno: Complete Guide

On the Arduino Uno, PWM (Pulse Width Modulation) is supported on digital pins 3, 5, 6, 9, 10, and 11. These pins can output analog-like signals using the analogWrite() function.
📐

Syntax

To generate a PWM signal on Arduino Uno, use the analogWrite(pin, value) function.

  • pin: The PWM-capable pin number (3, 5, 6, 9, 10, or 11).
  • value: The duty cycle from 0 (always off) to 255 (always on).

This function sets the pin to output a square wave with varying duty cycle, simulating analog voltage.

arduino
analogWrite(pin, value);
💻

Example

This example fades an LED connected to pin 9 using PWM. The LED brightness changes smoothly from off to fully on and back.

arduino
const int ledPin = 9;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(ledPin, brightness);
    delay(10);
  }
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(ledPin, brightness);
    delay(10);
  }
}
Output
LED connected to pin 9 smoothly fades in and out repeatedly.
⚠️

Common Pitfalls

Many beginners try to use analogWrite() on pins that do not support PWM, which will not produce the expected analog output.

Also, remember that analogWrite() does not generate a true analog voltage but a PWM signal that can be smoothed with external components.

Using pins 0 and 1 for PWM is not recommended because they are used for serial communication.

arduino
/* Wrong: Using analogWrite on pin 2 (no PWM) */
analogWrite(2, 128); // This will not produce PWM

/* Right: Use a PWM pin like 3 */
analogWrite(3, 128); // Correct PWM output
📊

Quick Reference

PWM PinDescription
3PWM output pin
5PWM output pin
6PWM output pin
9PWM output pin
10PWM output pin
11PWM output pin

Key Takeaways

PWM on Arduino Uno is available only on pins 3, 5, 6, 9, 10, and 11.
Use analogWrite(pin, value) to set PWM duty cycle from 0 to 255.
Do not use analogWrite on pins without PWM support; it won't work.
PWM simulates analog output by switching the pin on and off rapidly.
Avoid using pins 0 and 1 for PWM as they are reserved for serial communication.