Programming LED Pixels

While WLED handles most use cases without writing code, custom programming unlocks unlimited creative possibilities. This guide covers the essential tools and code patterns for programming addressable LEDs with Arduino, ESP32, and FastLED.

Development Environment

Install the Arduino IDE (2.x recommended) and add the ESP32 board package via the Board Manager. Install the FastLED library via the Library Manager. Connect your ESP32 via USB and select the correct board and port in Arduino IDE.

Your First Sketch: Rainbow

A basic rainbow animation in FastLED:

#include <FastLED.h>
#define NUM_LEDS 60
#define DATA_PIN 16
CRGB leds[NUM_LEDS];
uint8_t hue = 0;

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(128);
}

void loop() {
  fill_rainbow(leds, NUM_LEDS, hue++, 7);
  FastLED.show();
  FastLED.delay(20);
}

Common Patterns

Sound Reactivity

For beat-reactive LEDs, connect an INMP441 I2S microphone to your ESP32 and use the ArduinoFFT library to perform real-time frequency analysis. Map frequency bands to LED segments: bass (60-250 Hz) drives the center, mids (250-2000 Hz) fill outward, and treble (2000-16000 Hz) triggers sparkle effects at the edges.

Network Control

For network-controlled LEDs, use the ESP32's WiFi library combined with the ArtnetWifi or E131 library to receive streaming pixel data from professional software. This lets you drive LEDs from xLights, Resolume, MadMapper, or any Art-Net / E1.31 source over Wi-Fi or Ethernet.