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.
Right
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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro