NeoPixel effects
Drive a strip or stick of WS2812 LEDs through a color wipe, a rainbow and a theater chase.
Board
ESP32
3V3
GND
EN
23
VP
22
VN
TX
34
RX
35
21
32
GND
33
19
25
18
26
5
27
17
14
16
12
4
GND
0
13
2
D2
15
D3
D1
CMD
D0
5V
CLK
Wiring
| From | To board | Note |
|---|---|---|
| Strip 5V or VDC | 5V | Fine for a few LEDs. A long strip needs its own 5 V supply |
| Strip GND | GND | Join the grounds if the strip has its own supply |
| Strip DIN, through 330 Ω | GPIO 16 | The resistor goes next to the strip |
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32 Dev Module
#include <Adafruit_NeoPixel.h>
const int PIN = 16;
const int COUNT = 8; // LEDs on your strip or stick
Adafruit_NeoPixel strip(COUNT, PIN, NEO_GRB + NEO_KHZ800);
void wipe(uint32_t color) {
for (int i = 0; i < COUNT; i++) {
strip.setPixelColor(i, color);
strip.show();
delay(60);
}
}
void rainbow(unsigned long ms) {
unsigned long start = millis();
uint16_t hue = 0;
while (millis() - start < ms) {
for (int i = 0; i < COUNT; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536L / COUNT)));
}
strip.show();
hue += 256;
delay(20);
}
}
void chase(uint32_t color, unsigned long ms) {
unsigned long start = millis();
int step = 0;
while (millis() - start < ms) {
strip.clear();
for (int i = step % 3; i < COUNT; i += 3) strip.setPixelColor(i, color);
strip.show();
step++;
delay(120);
}
}
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(40); // about 15 %: easy on the eyes and on USB power
strip.show();
Serial.printf("%d LEDs on GPIO %d\n", COUNT, PIN);
}
void loop() {
Serial.println("effect: color wipe");
wipe(strip.Color(255, 0, 0));
wipe(strip.Color(0, 255, 0));
wipe(strip.Color(0, 0, 255));
Serial.println("effect: rainbow");
rainbow(5000);
Serial.println("effect: theater chase");
chase(strip.Color(255, 160, 0), 4000);
}S3
3V3
GND
3V3
TX
RST
RX
4
1
5
2
6
42
7
41
15
40
16
39
17
38
18
37
8
36
3
35
46
0
9
45
10
48
11
47
12
21
13
20
14
19
5V
GND
GND
GND
Wiring
| From | To board | Note |
|---|---|---|
| Strip 5V or VDC | 5V | Fine for a few LEDs. A long strip needs its own 5 V supply |
| Strip GND | GND | Join the grounds if the strip has its own supply |
| Strip DIN, through 330 Ω | GPIO 5 | The resistor goes next to the strip |
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32S3 Dev Module
#include <Adafruit_NeoPixel.h>
const int PIN = 5;
const int COUNT = 8; // LEDs on your strip or stick
Adafruit_NeoPixel strip(COUNT, PIN, NEO_GRB + NEO_KHZ800);
void wipe(uint32_t color) {
for (int i = 0; i < COUNT; i++) {
strip.setPixelColor(i, color);
strip.show();
delay(60);
}
}
void rainbow(unsigned long ms) {
unsigned long start = millis();
uint16_t hue = 0;
while (millis() - start < ms) {
for (int i = 0; i < COUNT; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536L / COUNT)));
}
strip.show();
hue += 256;
delay(20);
}
}
void chase(uint32_t color, unsigned long ms) {
unsigned long start = millis();
int step = 0;
while (millis() - start < ms) {
strip.clear();
for (int i = step % 3; i < COUNT; i += 3) strip.setPixelColor(i, color);
strip.show();
step++;
delay(120);
}
}
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(40); // about 15 %: easy on the eyes and on USB power
strip.show();
Serial.printf("%d LEDs on GPIO %d\n", COUNT, PIN);
}
void loop() {
Serial.println("effect: color wipe");
wipe(strip.Color(255, 0, 0));
wipe(strip.Color(0, 255, 0));
wipe(strip.Color(0, 0, 255));
Serial.println("effect: rainbow");
rainbow(5000);
Serial.println("effect: theater chase");
chase(strip.Color(255, 160, 0), 4000);
}C3
GND
GND
3V3
TX
3V3
RX
2
GND
3
9
GND
8
RST
GND
GND
7
0
6
1
5
10
4
GND
GND
5V
18
5V
19
GND
GND
Wiring
| From | To board | Note |
|---|---|---|
| Strip 5V or VDC | 5V | Fine for a few LEDs. A long strip needs its own 5 V supply |
| Strip GND | GND | Join the grounds if the strip has its own supply |
| Strip DIN, through 330 Ω | GPIO 4 | The resistor goes next to the strip |
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32C3 Dev Module
#include <Adafruit_NeoPixel.h>
const int PIN = 4;
const int COUNT = 8; // LEDs on your strip or stick
Adafruit_NeoPixel strip(COUNT, PIN, NEO_GRB + NEO_KHZ800);
void wipe(uint32_t color) {
for (int i = 0; i < COUNT; i++) {
strip.setPixelColor(i, color);
strip.show();
delay(60);
}
}
void rainbow(unsigned long ms) {
unsigned long start = millis();
uint16_t hue = 0;
while (millis() - start < ms) {
for (int i = 0; i < COUNT; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536L / COUNT)));
}
strip.show();
hue += 256;
delay(20);
}
}
void chase(uint32_t color, unsigned long ms) {
unsigned long start = millis();
int step = 0;
while (millis() - start < ms) {
strip.clear();
for (int i = step % 3; i < COUNT; i += 3) strip.setPixelColor(i, color);
strip.show();
step++;
delay(120);
}
}
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(40); // about 15 %: easy on the eyes and on USB power
strip.show();
Serial.printf("%d LEDs on GPIO %d\n", COUNT, PIN);
}
void loop() {
Serial.println("effect: color wipe");
wipe(strip.Color(255, 0, 0));
wipe(strip.Color(0, 255, 0));
wipe(strip.Color(0, 0, 255));
Serial.println("effect: rainbow");
rainbow(5000);
Serial.println("effect: theater chase");
chase(strip.Color(255, 160, 0), 4000);
}Parts
| Quantity | Part | Where to buy |
|---|---|---|
| 1× | ESP32 dev board | Buy at Amazon |
| 1× | NeoPixel Stick, 8 LEDs, or any WS2812B strip | Buy at Adafruit |
| 1× | 330 Ω resistor | |
| 1× | Optional 74AHCT125 level shifter | Buy at Adafruit |
| 3× | Jumper wires |
Amazon buy links may include an Associates tag, and this site may earn a commission from qualifying Amazon purchases at no extra cost to you. Adafruit links are direct.
Libraries
Adafruit NeoPixel
Load it
- In the Arduino IDE, install the esp32 board package and pick the board named above the sketch.
- Install the libraries listed above from the Library Manager.
- Paste the sketch, choose the board's port and upload. Hold BOOT if the upload stalls at Connecting.
- Close the IDE's serial monitor, then open the bench here to watch the output.
Field notes
- Each LED can draw about 60 mA at full white. Eight LEDs at the sketch's brightness are fine on USB. A metre or more needs its own 5 V supply and a 1000 µF capacitor across it.
- WS2812B LEDs on 5 V expect a data signal near 5 V. Most accept the ESP32's 3.3 V anyway. If the first LED flickers or stays dark, put a 74AHCT125 level shifter in the data line.
- No strip yet? The S3 and C3 DevKits have one WS2812 LED on the board: GPIO 38 (or 48 on the first S3 revision) and GPIO 8 on the C3. Set PIN to that and COUNT to 1.
- Use a current release of Adafruit NeoPixel. Old releases do not build on the 3.x Arduino core.
Not tested yet
- Not tested on hardware yet. Compiles for every board listed with Arduino-ESP32 core 3.3.12.