LED Strip WS2812B Issue with Arduino MEGA

Hi all,

I have an Arduino Mega, and I want to make a 2812B LED strip work. Right now, I'm just trying to figure out if my strip is functioning correctly. I simply want to display a solid color, for example, "green," on my LED strip.

I've placed the program below to display 300 LEDs in green on pin 2 of the Arduino. What happens is that with each program upload, around ten LEDs always display in white at the beginning of the strip, and the rest of the LEDs in green. Afterward, if I re-upload the same identical program, the LEDs turn red or some other color, and this happens every time I re-upload. Sometimes, random colors appear as well.

For now, I've only connected the + and - (5V) and the control wire to pin 2. I don't yet know what the other two wires are for.

Have you ever encountered this issue? I want to know if it's a problem with my LED strip or my program.

I have an external power supply: 220V ==> 5V / 20A / 200W and another backup supply of 220V ==> 5V / 10A / 50W.

C++
#include <FastLED.h>

#define NUM_LEDS 300
#define DATA_PIN 2

CRGB leds[NUM_LEDS];

void setup() {
  // Set the number of LEDs and the data pin
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  // Set brightness (between 0 and 255)
  FastLED.setBrightness(50);
  // Assign the color green to all LEDs
  fill_solid(leds, NUM_LEDS, CRGB::Green);
  // Display changes on the LED strip
  FastLED.show();
}

void loop() {
  // Your loop code here (if necessary)
}
Was this page helpful?