ws2812.ino
The addressable strip is THE NodeMCU project: one pin, 800 kHz of bit-banged pulses, instant wow factor. The sketch animates a comet; the discipline is the separate 5 V supply and ground plan.
Hardware required
An ESP-12E module (ESP8266EX, 2.4 GHz Wi-Fi) mounted on a NodeMCU / Wemos D1 mini board, powered over micro-USB. 16 WS2812B (strip or ring) + 5 V ≥ 1 A supply + 330-470 Ω resistor on data.
Wiring
Strip data through 470 Ω to D2, VDD to the external supply, strip GND tied to the board ground. A 1000 µF cap across the strip supply is advised.
How it works
NeoPixel assembles the 800 kHz NRZ frame (each bit is a pulse width) and blasts it in one shot on show(). setBrightness caps the current without changing relative colors. In the Arduino IDE, install the « esp8266 » package, select « NodeMCU 1.0 (ESP-12E Module) » then Upload (hold GPIO0 LOW if flashing fails). The A0 ADC reads 0-1 V (NodeMCU divider: 0-3.3 V).
Going further
Weather as color (hue = temperature), or a sweep synced with the previous sketch's servo.
ws2812.ino
// 16 WS2812B sur D2 (GPIO4) — bibliotheque Adafruit NeoPixel.
// Ruban alimente en 5 V EXTERNE, data via resistance 330-470 ohms.
#include <Adafruit_NeoPixel.h>
#define NB 16
#define PIN 4
Adafruit_NeoPixel ruban(NB, PIN, NEO_GRB + NEO_KHZ800);
int tete = 0;
void setup() {
ruban.begin();
ruban.setBrightness(80); // menage l'alimentation
ruban.clear();
ruban.show();
Serial.begin(115200);
}
void loop() {
ruban.clear();
ruban.setPixelColor(tete, 255, 80, 0);
ruban.setPixelColor((tete + NB - 1) % NB, 60, 20, 0); // trainee
ruban.setPixelColor((tete + 1) % NB, 60, 20, 0);
ruban.show(); // trame complete
tete = (tete + 1) % NB;
delay(60);
}