zaro

Which pins can output PWM?

Published in Arduino PWM Pins 2 mins read

The ability of an Arduino pin to output Pulse Width Modulation (PWM) depends on the specific board model, as only certain pins are equipped with the necessary hardware to generate these signals.

Understanding PWM on Arduino Boards

Pulse Width Modulation (PWM) is a technique used to achieve analog-like results with digital means. While digital pins can only be ON or OFF, PWM allows for varying the "on" time of a digital pulse within a fixed period, effectively controlling the average voltage supplied to a component. This is commonly used for tasks such as dimming an LED, controlling the speed of a DC motor, or generating audio tones.

Not all digital pins on an Arduino board support PWM output. The pins capable of PWM are specifically designated for this function, typically marked with a "~" symbol on the board itself.

PWM Pins for Common Arduino Boards

The following table details the pins that can output PWM for various popular Arduino board models:

Board PWM Pins
GIGA R1 2 - 13
Leonardo, Micro, Yún 3, 5, 6, 9, 10, 11, 13
UNO WiFi Rev2, Nano Every 3, 5, 6, 9, 10
MKR boards 0 - 8, 10, A3, A4

Note: For MKR boards, 'A3' and 'A4' refer to analog input pins that can also be used for PWM output.

How to Use PWM Pins

To generate a PWM signal on the designated pins, you typically use the analogWrite() function in the Arduino IDE.

  • Function Syntax: analogWrite(pin, value);
    • pin: The PWM-capable digital pin number.
    • value: An integer between 0 (always off) and 255 (always on). Intermediate values set the duty cycle of the PWM signal. For example, analogWrite(9, 127) would set pin 9 to approximately 50% duty cycle.

By understanding which pins support PWM and how to use the analogWrite() function, you can effectively control a wide range of components that require variable power or signal levels.