esp32 c3 rgb led example

Mastering ESP32 C3 RGB LED : A Hands-on Guide

By Daniel Thomas
AD

In the realm of Internet of Things (IoT), the ESP32 C3 microcontroller has emerged as a popular choice for its low power consumption, built-in Wi-Fi and Bluetooth connectivity, and generous GPIO pins. One captivating application of this microcontroller is controlling RGB LEDs, allowing for a wide range of colors and dynamic lighting effects. Let's delve into an engaging example of how to control an RGB LED using ESP32 C3.

The ESP32 C3 is equipped with PWM (Pulse Width Modulation) pins, which are perfect for controlling LED brightness. By manipulating the duty cycle of these pins, we can create a myriad of colors and lighting patterns. Before we dive into the code, let's set up our hardware.

Hardware Setup

The ESP32 C3 supports up to 20 GPIO pins and has built-in voltage regulation for LEDs. For our example, we'll connect an RGB LED to the ESP32 C3's GPIO pins GPIO19, GPIO18, and GPIO17, which corresponds to the red, green, and blue channels respectively.

AD
10 ESP32 Skills Every Maker Should Learn
10 ESP32 Skills Every Maker Should Learn
Controlling RGB Lights From ESP32 Web Server
Controlling RGB Lights From ESP32 Web Server
Modulo ESP32 Devkit V1 - Led RGB WS2812B - www.adrirobot.it
Modulo ESP32 Devkit V1 - Led RGB WS2812B - www.adrirobot.it

VCC of the LED should be connected to the 3.3V pin of the ESP32 C3, and GND should be connected to its ground pin. This way, the RGB LED will receive the power and ground signals from the microcontroller.

Coding the ESP32 C3 RGB LED Example

Now that our hardware is set up, let's dive into the code. We'll be using the Arduino IDE and its built-in libraries for this example.

Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
WLED ON XIAO ESP32
WLED ON XIAO ESP32
MicroPython: WS2812B Addressable RGB LEDs with ESP32 and ESP8266 | Random Nerd Tutorials
MicroPython: WS2812B Addressable RGB LEDs with ESP32 and ESP8266 | Random Nerd Tutorials

Setting up the Circuit

The first step is to include the LED library and define the RGB LED's pin connections.

```cpp #include < led.h > #define LED_PIN_RED GPIO19 #define LED_PIN_GREEN GPIO18 #define LED_PIN_BLUE GPIO17 ```

Initializing the RGB LED

Next, we initialize the LED and set it up with RGB channels.

AD
```cpp LED rgbled(LED_PIN_RED, LED_PIN_GREEN, LED_PIN_BLUE); ```

Creating a Color Wheel

A fantastic way to showcase RGB LED capabilities is by implementing a color wheel. This creates a smooth transition through the entire color spectrum.

πŸ’‘ ESP32 Web Server – Control an LED from Your Browser!
πŸ’‘ ESP32 Web Server – Control an LED from Your Browser!
Internet API for LED Pixel Strip based on ESP32
Internet API for LED Pixel Strip based on ESP32
DAY 5 β€” ESP32 Explained | Wi-Fi & Bluetooth Microcontroller Notes
DAY 5 β€” ESP32 Explained | Wi-Fi & Bluetooth Microcontroller Notes
ESP32 GPIO with ESP-IDF with LED Blinking example
ESP32 GPIO with ESP-IDF with LED Blinking example
ESP32 CYD with ESP-NOW: Receive Data | Random Nerd Tutorials
ESP32 CYD with ESP-NOW: Receive Data | Random Nerd Tutorials
How to Easily Control Addressable LEDs with an ESP32 or ESP8266 | WLED Project
How to Easily Control Addressable LEDs with an ESP32 or ESP8266 | WLED Project
```cpp void wheel(int val) { int r, g, b; val = val % 255; if (val < 85) { r = val * 3; g = 255 - (val * 3); b = 0; } else if (val < 170) { val = val - 85; r = 255 - (val * 3); g = 0; b = val * 3; } else { val = val - 170; r = 0; g = val * 3; b = 255 - (val * 3); } rgbled.setColor(r, g, b); // Send the computed color to the LED } ```

Implementing the Main Loop

Finally, in the main loop, we call the color wheel function, passing it the current millis() value. This gives us a smooth, spinning color wheel effect.

```cpp void loop() { wheel(millis() / 10); delay(10); } ```

Upload this code to your ESP32 C3 microcontroller, and you should see a mesmerizing color wheel effect on your connected RGB LED!

AD

Exploring the ESP32 C3 and RGB LED integration opens up a realm of possibilities in IoT and home automation. From smart lighting systems to responsive art installations, the future looks bright with these innovations. Happy tinkering!

ESP32 - LED Matrix | ESP32 Tutorial
ESP32 - LED Matrix | ESP32 Tutorial
ESP32 RGB LED Controller Web Server - Remote Color Picker
ESP32 RGB LED Controller Web Server - Remote Color Picker
ESP32-C3 Super Mini Pinout & Specs πŸ“Œβš‘
ESP32-C3 Super Mini Pinout & Specs πŸ“Œβš‘
ESP32 microcontroller with two circular 240*240 pixel displays (GCA901)
ESP32 microcontroller with two circular 240*240 pixel displays (GCA901)
ESP32 Simulator - LED chaser project πŸŽ‰πŸ˜-2022
ESP32 Simulator - LED chaser project πŸŽ‰πŸ˜-2022
250+ ESP32 Projects, Tutorials and Guides with Arduino IDE​ | Random Nerd Tutorials
250+ ESP32 Projects, Tutorials and Guides with Arduino IDE​ | Random Nerd Tutorials
ESP32 C3 Supermini Pinout
ESP32 C3 Supermini Pinout
ESP32-C3 Super Mini and an ILI9488 SPI TFT display
ESP32-C3 Super Mini and an ILI9488 SPI TFT display
ESP32 Explained: The Powerful IoT Board
ESP32 Explained: The Powerful IoT Board
Usefulelectronics/esp32-homekit-lightbulb
Usefulelectronics/esp32-homekit-lightbulb
How to Power the ESP32 Correctly ⚑
How to Power the ESP32 Correctly ⚑
WS2812B Music Reactive LED Using ESP32 & WLED
WS2812B Music Reactive LED Using ESP32 & WLED
three different types of electronic devices connected to each other, with the words display below them
three different types of electronic devices connected to each other, with the words display below them
ESP32 Pinout Guide: GPIO, Buttons & Ports Explained
ESP32 Pinout Guide: GPIO, Buttons & Ports Explained
AD