LEDs and Ardunio


First off newbie alert I'm new to all this electronics and playing with the Arduino (not new to coding). Eg, I have never soldered anything before... so that type of new. I have to start somewhere I suppose.

So I've picked a little project. I want to try working with the Arduino and LEDs and making them do different things before I try to move into anything more complex.

Ive decided to start at the right beginning and have 1 sole LED ( WS2812B) which I want to be solid red. I have supplied power to the LED and the Arduino which is all good and send my first sketch over (see below).

#include <FastLED.h>

#define LED_PIN     2
#define NUM_LEDS    1

void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

void loop() {
  leds[0] = CRGB(255, 0, 0);

I upload the code and suddenly LED turns red... great right... no....

Every so often my LED will flicker to a random colour (usually blue). Is this my code or more to do with the power supplied?

Thanks in advance and sorry for the super new question.

I got rid of the flicker by putting the LED strip on its own regulator, hook the commons together.

Ahhhh I've sussed out what you mean and it is all working as intended :smiley:

Thanks for the speedy reply and just so i understand what was happening. Was it due to the voltage going tot he LED from 2 sources... the USB Arduino and supply tot he LED?

I expect the LED strips are noisy.

Erm not currently... although i suspect they will be once I use more LEDs?

Currently, you have one led connected? Not a strip of which you are using only the first? If so, you shouldn't need a separate power supply or regulator at this stage. But you could try an electrolytic cap, 10uF+, near the led rather than near the Arduino, especially if the wires are long or thin.

When you change to a strip, that cap should be much larger, e.g. 470 or 1000uF, and you must use quality, thick wires to take the power from the separate PSU directly to the strip, possibly to both ends of the strip.

Also if the wires from the Arduino to the led are long or thin, put a ~500R resistor in the data line, near the led, and make sure a ground line goes in a pair with the data line back to the Arduino.

No, your code is fine. You didn't post a schematic (no fritzing pictures, please), so everyone is just guessing.

Do not power the WS2812 from the Arduino. One WS28xx LED is on the edge of the limit of what power the Arduino +5 pin can provide. The spec for the WS28xx 5V LEDs is "Power Supply Voltage VDD= +3.5~+5.5 V", so three AA batteries in series would work. If you use a good 5V PSU, then you can power the Arduino and many WS28xx LEDs from it.

The spec for the WS28xx chip recommends that you put a 104 capacitor (0.1 uf) across the +V and ground at the first LED. The spec also calls for a series resistor on the data line from the processor to the first LED. "To prevent the reflection and hot-swap protection, we suggest to connect a 33ohm resistor at the data input or output port for impedance."

Most of us ignore the series resistor and many ignore the capacitor. But it can't hurt to include them.

How did you get the "sole" LED? Did you cut one from a strip?

1 Like

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