First Blink (RGB LED)
The ESP32-S3-DevKitC-1 includes an addressable RGB LED (WS2812 / SK6812 compatible) that can display any color.
LED Details
| Specification | Value |
|---|---|
| Type | SK68XXMINI-HS (WS2812 compatible) |
| Control GPIO | 38 (V1.1) / 48 (V1.0) |
| Protocol | Single-wire, 800 kHz |
| Color Depth | 24-bit (8-bit per channel) |
Simple Digital Blink
This basic example toggles the LED data pin. The LED will appear dim white/off:
#include <Arduino.h>
#define LED_PIN 38 // Change to 48 for V1.0
void setup() { pinMode(LED_PIN, OUTPUT);}
void loop() { digitalWrite(LED_PIN, HIGH); delay(500); digitalWrite(LED_PIN, LOW); delay(500);}NeoPixel Library (Recommended)
-
Add library dependency
Add to
platformio.ini:lib_deps = adafruit/Adafruit NeoPixel@^1.12.0Use the
led_stripcomponent:Terminal window idf.py add-dependency "espressif/led_strip^2.4.1" -
Basic color cycling
#include <Arduino.h>#include <Adafruit_NeoPixel.h>#define LED_PIN 38 // GPIO38 for V1.1#define NUM_LEDS 1Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);void setup() {strip.begin();strip.setBrightness(50); // 0-255, start dimstrip.show(); // Initialize all pixels to off}void loop() {// Redstrip.setPixelColor(0, strip.Color(255, 0, 0));strip.show();delay(1000);// Greenstrip.setPixelColor(0, strip.Color(0, 255, 0));strip.show();delay(1000);// Bluestrip.setPixelColor(0, strip.Color(0, 0, 255));strip.show();delay(1000);// Whitestrip.setPixelColor(0, strip.Color(255, 255, 255));strip.show();delay(1000);}
Rainbow Effect
#include <Arduino.h>#include <Adafruit_NeoPixel.h>
#define LED_PIN 38#define NUM_LEDS 1
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() { strip.begin(); strip.setBrightness(30);}
void loop() { static uint16_t hue = 0;
// Use HSV color space for smooth rainbow uint32_t color = strip.gamma32(strip.ColorHSV(hue)); strip.setPixelColor(0, color); strip.show();
hue += 256; // Increment hue delay(20);}ESP-IDF Native LED Strip
Using ESP-IDF’s RMT peripheral for precise timing:
#include "led_strip.h"
#define LED_PIN 38#define LED_COUNT 1
static led_strip_handle_t led_strip;
void app_main(void) { led_strip_config_t strip_config = { .strip_gpio_num = LED_PIN, .max_leds = LED_COUNT, };
led_strip_rmt_config_t rmt_config = { .resolution_hz = 10 * 1000 * 1000, // 10MHz };
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
// Clear LED led_strip_clear(led_strip);
while (1) { // Set to red led_strip_set_pixel(led_strip, 0, 255, 0, 0); led_strip_refresh(led_strip); vTaskDelay(pdMS_TO_TICKS(1000));
// Set to green led_strip_set_pixel(led_strip, 0, 0, 255, 0); led_strip_refresh(led_strip); vTaskDelay(pdMS_TO_TICKS(1000));
// Set to blue led_strip_set_pixel(led_strip, 0, 0, 0, 255); led_strip_refresh(led_strip); vTaskDelay(pdMS_TO_TICKS(1000)); }}FastLED Alternative
#include <FastLED.h>
#define LED_PIN 38#define NUM_LEDS 1#define BRIGHTNESS 50
CRGB leds[NUM_LEDS];
void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(BRIGHTNESS);}
void loop() { // Cycle through hues static uint8_t hue = 0; leds[0] = CHSV(hue++, 255, 255); FastLED.show(); delay(20);}Status Indicator Patterns
Use the LED to indicate device state:
#include <Adafruit_NeoPixel.h>
#define LED_PIN 38Adafruit_NeoPixel led(1, LED_PIN, NEO_GRB + NEO_KHZ800);
void setStatus(const char* status) { uint32_t color;
if (strcmp(status, "wifi_connected") == 0) { color = led.Color(0, 255, 0); // Green } else if (strcmp(status, "wifi_connecting") == 0) { color = led.Color(255, 165, 0); // Orange } else if (strcmp(status, "error") == 0) { color = led.Color(255, 0, 0); // Red } else if (strcmp(status, "ota_update") == 0) { color = led.Color(0, 0, 255); // Blue } else { color = led.Color(0, 0, 0); // Off }
led.setPixelColor(0, color); led.show();}
void pulseStatus(uint32_t color, int duration_ms) { for (int i = 0; i < 255; i += 5) { led.setBrightness(i); led.setPixelColor(0, color); led.show(); delay(duration_ms / 100); } for (int i = 255; i > 0; i -= 5) { led.setBrightness(i); led.setPixelColor(0, color); led.show(); delay(duration_ms / 100); }}Troubleshooting
LED Stays Off
- Check GPIO number (38 for V1.1, 48 for V1.0)
- Verify library is using correct color order (GRB vs RGB)
- Set brightness above 0
Colors Are Wrong
The LED uses GRB color order:
// Correct for DevKitC-1Adafruit_NeoPixel strip(1, LED_PIN, NEO_GRB + NEO_KHZ800);
// Wrong orderAdafruit_NeoPixel strip(1, LED_PIN, NEO_RGB + NEO_KHZ800);LED Flickers
- Reduce brightness
- Add a 300-500Ω resistor in series with data line
- Ensure stable power supply
Next Steps
- USB Serial Configuration
- GPIO Reference
- GitHub Projects - More example code