Why Does analogWrite Not Work on This Pin?

Short answer: analogWrite only works on PWM capable pins. Not every pin supports PWM.

How to check PWM pins

  • Arduino Uno PWM pins are marked with a tilde. Pins 3, 5, 6, 9, 10, 11.
  • Arduino Nano and Mega have different PWM pin sets.
  • ESP32 uses PWM on many pins, but you still need to configure it in code.

Common mistakes

  • Using a non PWM pin for analogWrite.
  • Forgetting to set the pin mode to OUTPUT.
  • On ESP32, using Arduino style analogWrite without the proper PWM setup.

Quick test

Move your wire to a known PWM pin and try again.

Bottom line

analogWrite only works on PWM pins. Check your board pinout and use the right pins.

Related: What is PWM and why is my LED flickering? · Do I need a resistor for my LED? · What is the difference between digital and analog pins?