Esp32 Gpio Pwm Res
DodaTech
1 min read
In this tutorial, you'll learn about ESP32 PWM Resolution Causes Coarse Brightness Steps. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 LED brightness changes in visible steps instead of smooth gradients.
Quick Fix
Wrong
ledcSetup(0, 5000, 8); // 8-bit = 256 levels, visible steps
LED makes abrupt brightness jumps. Dark area steps are especially visible.
Right
ledcSetup(0, 5000, 12); // 12-bit = 4096 levels, smooth
ledcAttachPin(2, 0);
for (int duty = 0; duty < 4096; duty += 16) {
ledcWrite(0, duty);
delay(10);
}
LED fades smoothly from off to full brightness with no visible steps.
Prevention
Use 10-12 bit resolution for smooth dimming (1024-4096 levels). Higher resolution reduces max frequency. Balance resolution and frequency: 12-bit @ 5 kHz is good for LEDs. Use gamma correction for perceptually linear brightness.
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