Hi everyone,
So I have three Led strip lights (WS2812b) attached to my arduino uno data pins (4,5,9) and for some reason, the third strip (connected to pin 9) is the only one not working. Have I done something wrong in terms of the programming? or is this an electrical/physical issue? I am certain it is hooked up correctly so I am wondering if it is an issue with the LED.
Best,
Olivia
#include <FastLED.h>
#define LED_PIN 4
#define LED_PIN2 5
#define LED_PIN3 9
#define NUM_LEDS 152
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, LED_PIN2, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, LED_PIN3, GRB>(leds, NUM_LEDS);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
for (int i = 0; i <= 152; i++)
{
leds[i] = CHSV(0, 0, 75);
FastLED.show();
delay(2000);
}
for (int i = 0; i <= 111; i++)
{
leds[i] = CHSV(0, 0, 0);
}
FastLED.show();
delay(60000);
}
for (int i = 0; i <= 152; i++)
How many LEDs?
Please remember to use code tags when posting code
Hi there, sorry about that - will edit now!
Each strip has 152 LEDS.
omossuto:
Each strip has 152 LEDS.
So looping 153 times is incorrect.
Sorry, can you further explain how this is causing the issue for the third strip? (Connected to pin 9) Thank you so much for the help!
I don't know, but if you're debugging, go for the low-hanging fruit first.
153 iterations and only 152 LEDs doesn't look good - you (or rather the library) could be writing on memory you (it) don't own.
You begin with counting at the zero, not from zero, basically means the 0 is also a valid address (e.g a LED).
Looping from 0 to <=152 is what you would want if you have 153 LEDs. You do not.
You can loop from 0 to <=151. That would reference 152 LEDs.
You can loop from 0 to <152. That would reference 152 LEDs.
When you fix that, if it does not solve you problems with one of the 3 strips failing to light, try swapping.
The strips attached to pins 4 and 5 work? Unplug the failing strip from pin 9 and move the wire from pin 4 to pin 9.
Does that strip still work?
That checks if you are sending data on pin 9.
If it works (which I expect it will) then I would check that you are supplying proper power to the failing strip.
You defined the number of LEDs... #define NUM_LEDS 152
And then don't use it in your for/next statements.
Hi everyone, thanks so much for the help! I edited the code so that it loops 152 times instead of 153. This was not the issue, but a helpful reminder that 0 counts!
The actual issue, was that the LEDs were sent to me with the wires for power, ground, and data, soldered onto the wrong end of the strip - hence why, despite the programming being A-OK, the current was not running through the strip. Took me a while to notice, being a total newbie a this, but rest assured I will always check this from now on!