WS2812 LED bar/Using it/08. The first colours
Using it · 08 of 9

The first colours

Three wires from the header to an ESP32-S3: GND to GND, VCC to the 5V pin, DATA to GPIO 4, and NC left empty. Then a sketch that lights the bar red, green, blue and white from the top and walks the colours down one LED a second, printing which colour the top LED should show so the order can be checked.

Three wires, and NC left empty

Three wires, and NC left empty
ESP32-S3
Board
VCC from
5V, 4.6 V
DATA to
GPIO 4
HIGH margin
+0.08 V
5V to VCC, about 4.6 V with a USB cable in, and GPIO 4 to DATA. The LED wants 3.22 V for a HIGH and gets 3.3: through by 0.08 V.

Make the wires with the USB cable unplugged. The bar has no resistor on its data input and no capacitors, so it should not be plugged into a live board.

  • GND to GND.
  • VCC to 5V. On an ESP32-S3 with a USB cable in that pin is about 4.6 V, which the LEDs are happy with. Not 3V3: it is under their minimum.
  • NC to nothing.
  • DATA, the bottom pin, to GPIO 4, the pin the other single-pin TinkerBlock books use on an ESP32-S3.

On an Uno the same three wires go to GND, 5V and D6, and the DATA level is no question at all. This is the bar on an Uno, running a rainbow:

The TK33 on a LEGO baseplate, wired to an Uno, running a rainbow.

What the sketch does

It creates the strip with NEO_GRB, the order these LEDs read, sets a brightness of 40 out of 255, and sends one dark frame in setup() so nothing left from power-up survives.

Then once a second it writes five colours into the library's buffer and calls show(). The colours move down one LED each time, so red travels from the top LED to the bottom. The monitor prints what LED1 should be showing:

LED1 (top) should be red
LED1 (top) should be dark
LED1 (top) should be white

If the top LED matches the monitor, the wiring, the numbering and the colour order are all right.

Before you change it

At a brightness of 40 the bar draws 30 mA at most. The sketch's LEDS is 5 because the bar has five; a larger number only sends colours into LED5's dead-end output. For a second bar, give it its own pin and its own strip object, as Where the chain ends explains.

The code

tk33_first_colours.ino

Five colours, one per LED, moving down the bar once a second, at a brightness of 40 out of 255. The Serial Monitor says what the top LED should be showing, which checks the wiring, the pixel numbering and the colour order in one look.

// TK33 WS2812 RGB LED Bar: the first colours, on an ESP32-S3.
//
// Wiring, TK33 header top to bottom (LEDs facing you, pins left):
//   GND  -> ESP32 GND
//   VCC  -> ESP32 5V     (not 3V3: the LEDs want 3.5 V or more)
//   NC   -> nothing
//   DATA -> GPIO4
// Make the wires with the USB cable unplugged.
//
// Arduino IDE: Tools > Board > esp32 > ESP32S3 Dev Module,
// Tools > USB CDC On Boot > Enabled, then Tools > Port.
// Library Manager: install "Adafruit NeoPixel".
// Serial Monitor at 115200.

#include <Adafruit_NeoPixel.h>

const int DATA_PIN = 4;
const int LEDS = 5;      // five on this bar, and nothing after them

// NEO_GRB: this LED reads green first. NEO_KHZ800: 800 kbit/s.
Adafruit_NeoPixel bar(LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);

// Top to bottom at the start: red, green, blue, white, dark.
const uint32_t COLOUR[LEDS] = {
  0xFF0000, 0x00FF00, 0x0000FF, 0xFFFFFF, 0x000000
};
const char *NAME[LEDS] = { "red", "green", "blue", "white", "dark" };

int step = 0;

void setup() {
  Serial.begin(115200);
  delay(500);
  bar.begin();
  bar.setBrightness(40);  // of 255: 30 mA at most, all five white
  bar.show();             // a dark frame clears anything from power-up
}

void loop() {
  // Each colour moves one LED down per second; LED1 is pixel 0.
  for (int i = 0; i < LEDS; i++) {
    bar.setPixelColor(i, COLOUR[(i + LEDS - step) % LEDS]);
  }
  bar.show();             // 120 bits, then the line rests low

  Serial.printf("LED1 (top) should be %s\n",
                NAME[(LEDS - step) % LEDS]);
  step = (step + 1) % LEDS;
  delay(1000);
}

If the top LED shows green when the monitor says red, the colour order is wrong: the constant must be NEO_GRB. If nothing lights, check that the DATA wire is in the bottom hole and not in NC, one above it. On a classic ESP32 the same pin, GPIO 4, works unchanged.

When it does not work

Nothing lights, and the sketch runs.

Check the bottom hole first: DATA is the fourth pin from the top, and NC, one above it, is connected to nothing. Then check VCC is on the 5V pin and has a USB cable behind it, and that GND is joined. Last, check that DATA_PIN in the sketch matches the GPIO the wire is on.

The top LED shows green when the monitor says red.

The strip was created with the wrong colour order. The line must say NEO_GRB + NEO_KHZ800. Blue and white look right in either order, which is why red is the colour to check.

Only the first LED is wrong, or it flickers.

Only LED1 reads your pin. Look at the data level and the wire: keep the DATA jumper short, make sure the ground wire is in, and check VCC is on the ESP32's own 5V pin rather than a separate 5 V supply, which raises the HIGH the LED needs to 3.5 V.

Nothing appears in the Serial Monitor.

On an ESP32-S3 the sketch prints over the USB port only with Tools > USB CDC On Boot set to Enabled. Set it, upload again, and open the monitor at 115200. On a board with two USB sockets, use the one marked USB.

The colours are far too dim to see in daylight.

The sketch sets a brightness of 40 out of 255 to keep the current small. Raise it in setBrightness, up to 255. All five at full white is about 182 mA, which a USB port can supply; on a Wi-Fi project, see what five LEDs draw first.

Where this goes next

Six symptoms and where to look first for each.

When the colours are wrong

Edit this page — content/books/ws2812-led-bar/first-colours.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

WS2812 RGB LED Bar

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum