1.1 WS2812 RGB LED
Control the onboard WS2812 RGB LED on the ESP32-S3 multimedia board.
Overview
This example shows how to control the onboard WS2812 addressable RGB LED with the ESP32-S3 Arduino core. The sketch cycles through several colors and uses the built-in neopixelWrite() function, so no external LED library is required.
What You’ll Learn
Using
neopixelWrite()for WS2812 controlRGB color model basics
Timing with
delay()Simple brightness scaling to keep the LED comfortable to view
Before You Begin
Complete the setup steps in Preparation before continuing.
Note
Use the recommended Arduino IDE settings in Recommended Board Settings unless this lesson says otherwise.
Open the example sketch from the code package:
LAFVIN-ESP32-S3-Multimedia-Kit-main/1.Arduino/1.WS2812/1.WS2812.ino
This example uses the onboard WS2812 LED. No external wiring is required.
Signal |
ESP32-S3 |
|---|---|
Data |
GPIO 48 |
Note
If the LED does not light, confirm that you are using the kit’s onboard hardware and that the correct board and serial port are selected in Arduino IDE.
Upload and Test
Connect the board with a USB Type-C data cable.
Open
1.WS2812.inoin Arduino IDE.In the Tools menu, select
ESP32S3 Dev Moduleas the board and choose the correct serial port.Click Upload.
After the sketch starts, open Serial Monitor, set the baud rate to
115200, and watch the LED and serial messages at the same time.
After uploading, the onboard LED cycles through these states:
Red
Green
Blue
Yellow
White
Off
Each state lasts about 1 second. The Serial Monitor also prints the current color name.
How the Code Works
The ESP32 Arduino core includes a built-in neopixelWrite(pin, r, g, b) function that handles the WS2812 timing protocol, so this example does not need Adafruit NeoPixel or other LED libraries.
// Set the LED to red
neopixelWrite(48, 255, 0, 0);
// Set to blue at half brightness
neopixelWrite(48, 0, 0, 128);
In the provided sketch:
LED_PINis set to48BRIGHTNESSis limited to25to avoid excessive brightnessledWrite()scales the RGB values before sending them to the LEDThe loop cycles through red, green, blue, yellow, white, and off, with a 1-second delay between states
Try This Next
Change
BRIGHTNESSto make the LED dimmer or brighterReplace the fixed colors with your own RGB values
Reduce
delay(1000)to create a faster animation