How to Control LED Brightness on a Raspberry Pi With PWM
In this guide, we work with a pair of buttons to adjust the led brightness on a Raspberry Pi.
We will assume that you have your raspberry pi setup and ready to go. If you need help with this visit our blog.
What PWM Does to an LED
PWM, or Pulse Width Modulation, is a method that artificially lowers the voltage output of the Raspberry Pi’s GPIO (General Purpose Input/Output) pins. It’s artificial, as you don’t really reduce the voltage and just turn it on and off so fast that the overall voltage becomes lower than the real voltage you’re applying to it.
For an LED or Light-Emitting Diode, increasing the overall voltage makes it shine brighter, while decreasing it makes it dimmer. But since the Raspberry Pi has no analog output, we’re using PWM to control the LED’s brightness.
What You’ll Need
- 2 pushbuttons
- 3 resistors (250-550Ω will work. Use a lower rating if the LED is too dark.)
- 1 LED (any color)
- Breadboard
- Jumper wires
- Raspberry Pi (any model except the Pi Pico)
How to Use PWM to Control LED Brightness on a Raspberry Pi
In this guide, we are using use two buttons to make the LED shine brighter or dimmer with PWM. Pressing the “brighter” button increases the PWM output, while pressing the “dimmer” button decreases it.
Read More: How to Control LED Brightness on a Raspberry Pi With PWM