# Help with WS2812B led strip code

**URL:** <https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587>\
**Category:** General Guidance\
**Created:** [November 6, 2025, 12:34am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587 "2025-11-06T00:34:48Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![icemanmjb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/icemanmjb/32/1107407_2.png) [@icemanmjb](https://forum.arduino.cc/u/icemanmjb)\
**Post date:** [November 6, 2025, 12:34am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/1 "2025-11-06T00:34:48Z")

</div>

Hi i am new to arduino, i am using a ws2812b led strip of 10 leds and the code from the fastled firstlight exemple, which i am trying to change so i can light 2 leds at a time instead of one to get a 5 flash loop in white, was looking for a more of a flux capasiter look, if anyone can help me with this thanks

here is my code

```arduino
#include <FastLED.h>

///////////////////////////////////////////////////////////////////////////////////////////
//
// Move a white dot along the strip of leds. This program simply shows how to configure the leds,
// and then how to turn a single pixel white and then off, moving down the line of pixels.
// 

// How many leds are in the strip?
#define NUM_LEDS 10

// Data pin that led data will be written out over
#define DATA_PIN 3

// Clock pin only needed for SPI based chipsets when not using hardware SPI
//#define CLOCK_PIN 8

// This is an array of leds. One item for each led in your strip.
CRGB leds[NUM_LEDS];

// This function sets up the ledsand tells the controller about them
void setup() {
	// sanity check delay - allows reprogramming if accidently blowing power w/leds
   	delay(2000);

      
      FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
      
}

// This function runs over and over, and is where you do the magic to light
// your leds.
void loop() {
   // Move a single white led 
   for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
      // Turn our current led on to white, then show the leds
      leds[whiteLed] = CRGB::White;

      // Show the leds (only one of which is set to white, from above)
      FastLED.show();

      // Wait a little bit
      delay(100);

      // Turn our current led back to black for the next loop around
      leds[whiteLed] = CRGB::Black;
   }
}

```

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [November 6, 2025, 1:17am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/2 "2025-11-06T01:17:15Z")

</div>

Your code will display 10 leds. Where do you think the code says 5?

BTW, in a for loop the last arg is normally whiteLed++ or ++whiteLed

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [November 6, 2025, 7:04am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/3 "2025-11-06T07:04:56Z")

</div>

What is happening now and what do You want to happen?

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [November 6, 2025, 7:10am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/4 "2025-11-06T07:10:00Z")

</div>

> [@icemanmjb](#):
>
> flux capasiter

This is not a real thing. Be descriptive.

> [@icemanmjb](#):
>
> `WS2811`

The WS2811 light three LEDs at one address. It is not the same as WS2812B.

---

<div class="post-metadata">

**Author:** ![pattl](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pattl/32/332315_2.png) [@pattl](https://forum.arduino.cc/u/pattl)\
**Post date:** [November 6, 2025, 7:10am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/5 "2025-11-06T07:10:34Z")

</div>

did any LED´s light´s up?  
is the strip dark?  
did you use the right Voltage?

---

<div class="post-metadata">

**Author:** ![pattl](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pattl/32/332315_2.png) [@pattl](https://forum.arduino.cc/u/pattl)\
**Post date:** [November 6, 2025, 7:33am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/6 "2025-11-06T07:33:43Z")

</div>

and im seeing one thing in xour discription you use an WS2812b  
in your setup you use the ws2811  
change it with the line below and try again

```
`FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical`

```

---

<div class="post-metadata">

**Author:** ![icemanmjb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/icemanmjb/32/1107407_2.png) [@icemanmjb](https://forum.arduino.cc/u/icemanmjb)\
**Post date:** [November 6, 2025, 1:51pm UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/7 "2025-11-06T13:51:53Z")

</div>

Hi , yes the leds light up, they individually light up in a white led chaser effect, of 10 leds , need help with the code so I can keep the same effect but have 2 leds light up _simultaneously in the chaser instead of one_

Thanks..

---

<div class="post-metadata">

**Author:** ![pattl](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pattl/32/332315_2.png) [@pattl](https://forum.arduino.cc/u/pattl)\
**Post date:** [November 6, 2025, 2:03pm UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/8 "2025-11-06T14:03:30Z")

</div>

Okay, perfect. The LEDs get their signals from the Arduino. There are two different types of strips: one runs on 5V, where every LED can be controlled individually, and the other runs on 12V, where three LEDs share the same signal and light up together.

For me, the Adafruit NeoPixel library is much easier to use — you can give that one a try.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [November 6, 2025, 2:10pm UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/9 "2025-11-06T14:10:51Z")

</div>

> [@icemanmjb](#):
>
> 2 leds light up _simultaneously_

End the loop early.  
Add one more line addressing the next LED.

```arduino
   for(int whiteLed = 0; whiteLed < NUM_LEDS - 1; whiteLed = whiteLed + 1)
.
.
leds[whiteLed] = CRGB::White;
leds[whiteLed + 1] = CRGB::White;

```

---

<div class="post-metadata">

**Author:** ![oldcurmudgeon](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oldcurmudgeon/32/1280882_2.png) [@oldcurmudgeon](https://forum.arduino.cc/u/oldcurmudgeon)\
**Post date:** [November 6, 2025, 5:14pm UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/10 "2025-11-06T17:14:15Z")

</div>

> [@xfpd](#):
>
> End the loop early.  
> Add one more line addressing the next LED.
> 
> ```arduino
> for(int whiteLed = 0; whiteLed < NUM_LEDS - 1; whiteLed = whiteLed + 1)
> .
> .
> leds[whiteLed] = CRGB::White;
> leds[whiteLed + 1] = CRGB::White;
> 
> ```

And adjust the loop condition...

for(int whiteLed = 0; whiteLed \<**( NUM\_LEDS - 1)/2**; whiteLed = whiteLed + **2**

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [November 6, 2025, 11:51pm UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/11 "2025-11-06T23:51:54Z")

</div>

> [@oldcurmudgeon](#):
>
> And adjust the loop condition...

That loop

```arduino
for (int whiteLed = 0; whiteLed <( NUM_LEDS - 1)/2; whiteLed = whiteLed + 2) {

```

does 0, 2, 0, 2 forever.

(NUM\_LEDS - 1) / 2 = 9 / 2 = 4.

So whatever you were going for is not happening.

But why are you even trying to reduce the number of steps by half? A pixel takes ten steps to cross the strip. A two-pixel train will still take ten steps…

@xfpd was close, and had he tested the code the obvious flaw woukd have an obvious solution- you gotta turn off the things you turn on:

```arduino
     // Turn our current leds back to black for the next loop around
     leds[whiteLed] = CRGB::Black;
     leds[whiteLed + 1] = CRGB::Black;

```

Which plays out over nine steps thusly:

```arduino
XX........
.XX.......
..XX......
...XX.....
....XX....
.....XX...
......XX..
.......XX.
........XX
XX........
.XX.......
..XX......
...XX.....
....XX....

```

Which is pretty. When trains get longer or sometimes even with just two, you can write it so the train enters from the left and exits to the right, like

```arduino
..........
X.........
XX........
.XX.......
..XX......
...XX.....
....XX....
.....XX...
......XX..
.......XX.
........XX
.........X
..........
..........

```

Where I've added a few beats of no lights at all between passes.

These tiny things can get bit complicated. I don't think FastLED does bounds checking, so you can't just write to pixels that have no memory allocated. This is one advantage of Adafruit's Neopixel library… you can write a simpler loop and just place the train anywhere, into negative indices or beyond the last real pixel. Bounds check will mean when the train is off screen, so to speak, it does no harm.

I draw things like this out as I have done above. This informs crafting the loops, or in the case of non-blocking implementation, writing the maths that make each step.

a7

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [November 7, 2025, 4:17am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/12 "2025-11-07T04:17:58Z")

</div>

This code moves a train along a strip. It moves one step per iteration of the _loop_() function.

```arduino
# include <FastLED.h>

// Move a train of pixels along a strip of leds.

# define NUM_LEDS 27 // size of strip
# define DATA_PIN 3

CRGB leds[NUM_LEDS];

# define TRAIN 5 // length of train

void setup() {
 FastLED.addLeds<WS2811, DATA_PIN, RBG>(leds, NUM_LEDS);
}

void loop() {
 static int caboose = -TRAIN; // train caboose location

// move the caboose pixel to be the new engine pixel
// turn off the caboose
 if (caboose > -1 && caboose < NUM_LEDS)
   leds[caboose] = CRGB::Black;

// turn on what will be the new engine
 int newEngine = caboose + TRAIN;
 if (newEngine > -1 && newEngine < NUM_LEDS)
   leds[newEngine] = CRGB::Red;

 FastLED.show();
 delay(100); // sue me

 caboose++; // move train one step down the strip, reset if done
 if (caboose == NUM_LEDS) {
   delay(1300);
   caboose = -TRAIN;
 }
}

```

  
The timing is done with delays, but there are no for \*loops\*. It's more than half way to being non-blocking.

a7

---

<div class="post-metadata">

**Author:** ![icemanmjb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/icemanmjb/32/1107407_2.png) [@icemanmjb](https://forum.arduino.cc/u/icemanmjb)\
**Post date:** [November 7, 2025, 1:52pm UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/13 "2025-11-07T13:52:29Z")

</div>

Ok , thanks for all the help, much appreciated 👍

---

<div class="post-metadata">

**Author:** ![icemanmjb](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/icemanmjb/32/1107407_2.png) [@icemanmjb](https://forum.arduino.cc/u/icemanmjb)\
**Post date:** [November 11, 2025, 12:37am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/14 "2025-11-11T00:37:32Z")

</div>

hi thanks for you code, this is the effect i was looking for, is running in green at the moment, would you be able to help me with the code in changing the color, would like it to run in white then maybe i can learn from the from you code to change to other colors

thanks, ic

---

<div class="post-metadata">

**Author:** ![TailsLP](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tailslp/32/1244900_2.png) [@TailsLP](https://forum.arduino.cc/u/TailsLP)\
**Post date:** [November 11, 2025, 2:24am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/15 "2025-11-11T02:24:18Z")

</div>

> [@icemanmjb](#):
>
> changing the color, would like it to run in white

You can just… read _that_ same code and find out yourself how to do so…

```arduino
// [...]

 if (newEngine > -1 && newEngine < NUM_LEDS)
   leds[newEngine] = CRGB::Red; // change "Red" to "White"!
 FastLED.show();

// [...]

```

There are also other ways to change LED’s color which are documented in the FastLED docs.

> **[Controlling leds](https://github.com/FastLED/FastLED/wiki/Controlling-leds)**
>
> The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues&...

> [@icemanmjb](#):
>
> is running in green

Hmm, are you using alto’s exact same code? If that’s so, watch out for this (specifically the part that says “RGB“):

```arduino
void setup() {
 FastLED.addLeds<WS2811, DATA_PIN, RBG>(leds, NUM_LEDS);
}

```

You should change “RGB” to “GRB”; otherwise, if you are going to, say, change the color to red, you’ll actually be getting green instead. “GRB” is the correct colour order for your LED strip. See more here:

> **[Rgb calibration](https://github.com/FastLED/FastLED/wiki/Rgb-calibration)**
>
> The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues&...

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [November 11, 2025, 3:13am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/16 "2025-11-11T03:13:28Z")

</div>

> [@TailsLP](#):
>
> “GRB” is the correct colour order for your LED strip

RGB was used in the original code. It's hard to see errors when you make white pixels!

wokwi seems to have GRB strips.

a7

---

<div class="post-metadata">

**Author:** ![TailsLP](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tailslp/32/1244900_2.png) [@TailsLP](https://forum.arduino.cc/u/TailsLP)\
**Post date:** [November 11, 2025, 3:42am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/17 "2025-11-11T03:42:10Z")

</div>

> [@alto777](#):
>
> RGB was used in the original code. It's hard to see errors when you make white pixels!

Yup. I just wanted to make sure OP knew that not all models have the same RGB order (OP mentioned that the LEDs light up green instead of the expected red from your code, although they didn't complain about it).

Sorry if I wasn’t clear 😄

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [November 11, 2025, 5:32am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/18 "2025-11-11T05:32:43Z")

</div>

> [@TailsLP](#):
>
> Yup

You changed your user name.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 10, 2026, 5:33am UTC](https://forum.arduino.cc/t/help-with-ws2812b-led-strip-code/1412587/19 "2026-05-10T05:33:21Z")

</div>

Closed on May 10, 2026, 5:33am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
