How to Blink an RGB LED with ESP32 in Different Colors
Introduction
RGB LEDs allow you to create multiple colors by mixing red, green, and blue light. In this tutorial, we will use an ESP32 to control an RGB LED, making it blink in different colors.
Components Required
- ESP32 board
- Common cathode RGB LED
- Jumper wires
- Breadboard
Circuit Connection
| RGB LED Pin | ESP32 Pin |
|---|---|
| Red (R) | GPIO 25 |
| Green (G) | GPIO 26 |
| Blue (B) | GPIO 27 |
| GND | GND |
Arduino Code for Blinking RGB LED
Explanation
setColor(r, g, b)sets the brightness of the red, green, and blue LEDs using PWM.- The program cycles through 7 different colors (Red, Green, Blue, Yellow, Cyan, Magenta, White) and then turns the LED off.
delay(1000)keeps each color on for 1 second.
Conclusion
This simple program makes an RGB LED blink in different colors using an ESP32. You can modify it to create fading effects or use sensors for color changes.
🔧 Try it out and share your thoughts in the comments! 🚀
0 Comments