You can dim an LED in a few different ways, depending on whether you want to do it electronically or mechanically.

1. The easiest way — use PWM (Pulse-Width Modulation)
If you’re controlling your LED with something like an Arduino, Raspberry Pi, or any microcontroller:
- PWM rapidly turns the LED on and off many times per second.
- By changing the ratio of on-time to off-time (called the duty cycle), you control how bright the LED appears.
- Example Arduino code:
cppCopyEditint ledPin = 9; // Must be a PWM-capable pin
int brightness = 0;
int fadeAmount = 5;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
analogWrite(ledPin, brightness); // Send PWM signal
brightness += fadeAmount; // Change brightness
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount; // Reverse direction at limits
}
delay(30); // Small delay for smooth fading
}
💡 analogWrite() gives values from 0 (off) to 255 (full brightness).
2. Analog dimming — change the current
If you’re working with a simple battery + resistor LED setup:
- Use a potentiometer (variable resistor) in series with the LED to reduce current → dimming the LED.
- This method wastes more energy as heat and is less efficient than PWM.
3. Use a constant-current LED driver with dimming control
- Many LED driver modules have a dimming pin you can control with a PWM signal or a control voltage (0–10V, for example).
- Ideal for high-power LEDs or lighting strips.
4. Software dimming (if already using microcontroller)
- Instead of PWM, you can manually blink the LED at different patterns, but this is less smooth and less efficient.