Skip to content

ESP32 PWM LED Flickers or Does Not Dim

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 PWM LED Flickers or Does Not Dim. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 PWM control of an LED results in flickering, no change in brightness, or incorrect PWM frequency.

Quick Fix

Wrong

ledcSetup(0, 5000, 8);
ledcAttachPin(2, 0);
ledcWrite(0, 128);  // LED does not dim
LED stays at full brightness or flickers at low duty cycles.
const int freq = 5000;
const int res = 8;
const int channel = 0;
ledcSetup(channel, freq, res);
ledcAttachPin(2, channel);
// Fade from dim to bright
for (int duty = 0; duty <= 255; duty++) {
  ledcWrite(channel, duty);
  delay(10);
}
LED smoothly fades from off to full brightness over 2.5 seconds.

Prevention

Set PWM frequency at least 1 kHz to avoid visible flicker. Use 8-16 bit resolution for smooth dimming. Attach pin to channel after setup. Use separate channels for multiple LEDs. Increase frequency for inductive loads.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What PWM frequency should I use?

1-5 kHz for LEDs (above visible flicker). 50 Hz for servos. 20 kHz to avoid audible noise from coils.

How many PWM channels does ESP32 have?

ESP32 has 16 PWM channels, each with independent frequency and resolution. Multiple pins can share a channel.

Can I use analogWrite() on ESP32?

analogWrite() is not available in ESP32 Arduino. Use ledcSetup()/ledcWrite() instead for PWM control.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro