I'm trying to re-use a piece of example code I found here:


And I only have 5 LEDs in my strip, so I changed the define NUM_LEDs to 5, but when compiling with that value, I get a compilation error. with the define at 6 it works tho, but the 5th LED wouldn't turn on. Here is my code:

#include <FastLED.h>
#define LED_PIN     7
#define NUM_LEDS    6
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

void loop() {

  leds[0] = CRGB(0, 10, 0);
  leds[1] = CRGB(10, 0, 0);
  leds[2] = CRGB(0, 10, 10);
  leds[3] = CRGB(10, 10, 0);
  leds[4] = CRGB(10, 10, 10);
  leds[0] = CRGB(0, 0, 0);
  leds[1] = CRGB(0, 0, 0);
  leds[2] = CRGB(0, 0, 0);
  leds[3] = CRGB(0, 0, 0);
  leds[4] = CRGB(0, 0, 0);


So in the code, I've set the first LED to green, seccond one to red, third one to blue, 4th one to yellow, and the 5th one to white. As you can see in the picture they all light up correctly but the 5th one which stays blank, and I don't know why. I have tested this LED individually and it works perfectly well so it's not a hardware problem. I would encourage anyone who wants to test this code on 5 LEDs and let me know if it works for them, I'd be surprised it it did, but if you have a better solution for me, I would appreciate it.

Thanks.enter image description here

  • What is the compilation error you get when setting the number of LEDs to 5? Does the 5th LED turn on if you set it to another color, let’s say red? You said it works individually and, looking at the picture, it seems you have wired the LEDs yourself: have you checked the data line is soldered correctly and you don’t have a flickering connection? – Roberto Lo Giacco Jun 17 '19 at 1:13
  • Holly crap, I literaly did this earlier today and had a compilation error, but I just tried it now, and the error went away. no idea why. By the way I got these PCBs made and you're right, I did solder it myself – james Jun 17 '19 at 2:42
  • but the 5th LED still doesn't light up. It might be a problem with the circuit but I really think it's the code. If someone can test this code on a strip of 5 LEDs it would be nice if they could confirm if it's a hardware problem or the code. – james Jun 17 '19 at 2:44
  • Your code is non optimized but correct: all LEDs should light up but very dim for half a second and turn off for another half. Please note you are setting a value of 10 out of 255, meaning you are about at 5% power. Try replacing 10 with 255 and see the increased brightness, but take into consideration the increased power consumption as well: the power supply for the strip must be able to safely deliver that much current. – Roberto Lo Giacco Jun 17 '19 at 10:11
  • what happens if you code it for 10 LEDs, does the last one work then? – dandavis Jun 17 '19 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.