← Projects

LED Controller

A custom snowfall effect for a programmable LED strip, running on an ESP32 and controlled from my phone.

Personal project

View code
The control page. The strip on the left mirrors what the real LEDs show.

The ask

I wanted LED lights that looked like snow falling, and nothing on the market did it the way I pictured. So I built my own: a programmable strip, an ESP32, and a control page on my phone, with no app or cloud account needed.

How I built it

It only works with programmable LED strips (I used WS2812B). Each LED on those has its own tiny chip, so every one can be a different color, and that’s what makes effects like rainbow possible. A regular RGB strip changes all its LEDs together and needs different wiring. The ESP32 does everything else. It joins my Wi-Fi, serves the control page, and drives the LEDs. Picking a color on the page sends a small request to the board, and the firmware redraws the strip about 60 times a second.

  • Falling snow. Flakes start at the top of the strip and fall at their own speeds, gliding between LEDs instead of jumping.
  • The page lives on the board. The HTML is compiled into the firmware, so there’s no separate server.
  • Smooth on a slow device. Dragging a slider fires dozens of events a second, so the page batches them and sends at most one request every 80 ms.
  • Remembers settings. Settings are saved to flash, so the strip comes back the same after a power cut. Flash wears out with too many writes, so it saves once, 2 seconds after your last change.
  • Works without the router. If it can’t join Wi-Fi, it makes its own network so the page still loads.
C++ (Arduino)
the firmware
ESP32
Wi-Fi, web server, and LED output
FastLED
LED timing, effects, and power limits
HTML + CSS + JS
the control page and live preview
Preferences
saving settings to flash
Python
a script that embeds the page in the firmware

The snow, falling

for (Flake& f : flakes) {
  if (!f.active) continue;
  f.pos -= f.speed;

  // Fell off the bottom: free this slot for a new flake.
  if (f.pos < 0) {
    f.active = false;
    continue;
  }

  // Split the flake across two LEDs so it glides instead of jumping.
  int i = (int)f.pos;
  uint8_t below = (uint8_t)(255 * (1.0f - (f.pos - i)));
  leds[i] += CRGB(SNOW_WHITE).nscale8_video(below);
  if (i + 1 < NUM_LEDS) leds[i + 1] += CRGB(SNOW_WHITE).nscale8_video(255 - below);
}

A flake between two LEDs lights both, in proportion. That’s what makes it glide.

Running it off the board

I powered the strip from the ESP32’s 5V pin instead of adding a separate power supply. That’s fine for a short strip, but the 5V pin comes straight from USB, which only gives about 500 mA. Thirty LEDs on full white can ask for 1.8 A. Instead of adding hardware, I capped it in code: FastLED dims the whole strip if a color would draw more than 450 mA.

The power cap

// Strip runs off USB through the ESP32,
// so keep total draw under USB's ~500 mA
#define MAX_MILLIAMPS 450

FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, MAX_MILLIAMPS);

What I'd change

Try the controls

A mini version of the control page. The column of dots stands in for the strip.

Color