If you’ve driven LEDs with PWM on a Raspberry Pi and noticed annoying flicker—especially at low brightness—you’re not alone. The issue isn’t your wiring; it’s the Pi’s limited PWM capabilities and how Linux handles timing.
But don’t switch to an Arduino just yet. Here’s how to fix (or significantly reduce) flicker on the Pi.
Why Flicker Happens
The Raspberry Pi uses software-timed or low-frequency hardware PWM by default:
GPIO PWM via RPi. GPIO or wiringPi: software-based → jittery
Hardware PWM (GPIO 12/13/18/19): only ~1–10 kHz — too low for smooth dimming
Human eyes can detect flicker below 200–400 Hz, especially in peripheral vision
Result? Your “50% brightness” LED looks like a strobe light.
Solution 1: Use Higher PWM Frequency (Hardware PWM)
If you’re using GPIO 12, 13, 18, or 19, you can access the Pi’s hardware PWM module with higher frequency.
Why it works:
20 kHz is far above human flicker fusion threshold
Hardware-timed → no OS jitter
Solution 2: Use an External PWM Driver (Best for Precision)
For critical applications (e.g., photography lighting, medical devices), offload PWM to a dedicated chip:
Solution 2: Use an External PWM Driver (Best for Precision)
PCA9685 (I²C, 12-bit, up to 1.6 kHz — but very stable)
TLC5947 (SPI, 12-bit, grayscale PWM)
These run independently of the Pi’s OS, eliminating scheduling jitter entirely.
Bonus: 12-bit resolution (4096 levels) vs. Pi’s 8-bit (256 levels)
Pro Tips
Use constant-current drivers for high-power LEDs—PWM on voltage alone causes color shift.
Add a small capacitor (10–100µF) near the LED to smooth residual ripple.
Test in real conditions: Flicker is worse in dim rooms or when moving your eyes.
Final Thought
The Raspberry Pi isn’t a real-time controller—but with the right tools (pigpio or external drivers), you can still build flicker-free LED systems that look professional.
Top comments (0)