Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

WS2812B strip with Arduino Mega 2560 — 300 LEDs and how to power them

Drive a 5 m, 300-LED WS2812B strip from an Arduino Mega 2560 on pin 6, with a 5 V 10 A supply, power injection and a comet animation that fits in RAM.

Arduino C++Verified — core avr 1.8.8, Adafruit NeoPixel 1.15.5, 3 Nov 2026Compile-only

Community draft — report a mistake

Lighting up a whole room, a staircase or a festival display takes hundreds of LEDs — and that is where the Mega’s 8 KB of RAM matters. A 5-metre, 300-LED strip uses 900 bytes of buffer, which the Mega handles comfortably.

The data comes from pin 6 through a 330 Ω resistor. The power does not: the strip runs from its own 5 V supply, with the grounds joined. The sketch runs a colourful comet that fades as it goes.

Wiring

Arduino Mega 2560Only the pins used are shown · 5 V logic5 V 10 A SMPSWS2812B addressable RGB LED strip (NeoPixel)330 Ω+-GNDD6DIN5VGNDDOUT (not connected)
Also needed: 5 V 10 A SMPS (enclosed type; its 230 V side wired by an electrician), 330 Ω resistor, 1000 µF / 10 V capacitor.
Every connection
Arduino Mega 2560WS2812B addressable RGB LED strip (NeoPixel)WireNotes
D6DINgreenVia 330 Ω — Resistor close to the first LED.
5 V 10 A SMPS · +5Vred1000 µF across + and − at the strip input. Inject 5 V again at the far end of a 5 m strip.
5 V 10 A SMPS · -GNDblack
GNDGNDblackCommon ground between Mega and supply — the data signal needs it.

5 V (about 60 mA per LED at full white) part, 5 V board. The strip expects a data HIGH of about 3.5 V at 5 V supply. From ESP32 or Pico the 3.3 V signal often works with short wires, but to be safe drive DIN through a 74AHCT125 (or 74HCT125) powered from 5 V.

Board quirks

  • Each LED takes 3 bytes of RAM: 300 LEDs = 900 bytes, about 11 % of the Mega’s 8 KB. The same strip would eat almost half an Uno’s RAM.
  • strip.show() for 300 LEDs takes about 9 ms with interrupts off. Serial input can drop bytes at high baud rates during that time.
  • Never power 300 LEDs through the Mega. At full white they could draw 18 A; setBrightness(60) keeps this animation to a few amps.
  • Feed 5 V at both ends (or every 2–3 m) with thick wire, or the far end turns yellow-brown.
  • The SMPS’s 230 V terminals must be covered and wired by someone qualified. Only the 5 V side is part of this build.

Code

ws2812b-mega.inoArduino C++Open in PlaygroundOpen in Playground
// Long WS2812B strip (300 LEDs = 5 m at 60/m) on an Arduino Mega 2560: a running "comet".
// DIN → D6 through 330 Ω, strip 5V and GND from a 5 V 10 A supply, supply GND joined to Mega GND.
// 300 LEDs use 900 bytes of RAM — easy on the Mega's 8 KB.
#include <Adafruit_NeoPixel.h>

const uint8_t DATA_PIN = 6;
const uint16_t NUM_LEDS = 300;
Adafruit_NeoPixel strip(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.setBrightness(60);  // ~25 %: caps worst-case current around 4-5 A for 300 LEDs
  strip.clear();
  strip.show();
  Serial.print(F("Strip ready, free RAM after begin: "));
  extern int __heap_start, *__brkval;
  int v;
  Serial.println((int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval));
}

void loop() {
  static uint16_t pos = 0;
  static uint16_t hue = 0;
  for (uint16_t i = 0; i < NUM_LEDS; i++) {  // fade every LED a little
    uint32_t c = strip.getPixelColor(i);
    uint8_t r = (c >> 16) * 3 / 4, g = (c >> 8 & 0xFF) * 3 / 4, b = (c & 0xFF) * 3 / 4;
    strip.setPixelColor(i, r, g, b);
  }
  strip.setPixelColor(pos, strip.ColorHSV(hue));
  strip.show();  // ~9 ms for 300 LEDs; interrupts are off meanwhile
  pos = (pos + 1) % NUM_LEDS;
  hue += 200;
  delay(10);
}

Library: Adafruit NeoPixel (Adafruit) — compiled with Adafruit NeoPixel 1.15.5.

Expected serial output

Serial Monitor · 115200Output
Strip ready, free RAM after begin: 6934

Common errors

First LED flickers or wrong colours further down

No common GND between Mega and supply, or no 330 Ω resistor. Add both.

Colours fade to orange towards the end

Voltage drop along the strip. Inject power at the far end.

↑↓ to move · Enter to open