0

I've got an Arduino with a WS2812 hooked up to it, powered by the USB on my computer and I am trying to run the following code:

#include <FastLED.h>

#define NUM_LEDS 144
#define DATA_PIN 6
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.show();
}

void loop() {
  for(int dot = 0; dot < NUM_LEDS; dot++) { 
    fill_solid(leds, NUM_LEDS, CRGB::Red);
    leds[dot] = CRGB::Black;
    leds[dot] = CRGB::Blue;
    FastLED.show();
    leds[dot] = CRGB::Red;
    delay(30);
  }
}

void setAll() {

  FastLED.show();
}

What this does is sets all the LEDs to red, then goes through each one turning it off, then to blue and then back to red.

For some reason, it gets X number of LEDs along and then crashes. By crashes I mean the Arduino disconnects itself from the computer, but the Arduino stays on with the LED strip still powered up.

Any ideas? This is a genuine Uno and I can run any of the FastLED or NeoPixel examples for hours on end without an issue

9
  • Have you checked the memory footprint? Jan 3, 2017 at 23:50
  • I'm not 100% sure how I go about this, but when I upload the code, it says its taking up X bytes which if I recall was about 25%. Also, I can throw any of the complex FastLED examples onto it and run them without any problems at all
    – K20GH
    Jan 3, 2017 at 23:53
  • Have you checked the power requirements? Circuit? Jan 3, 2017 at 23:59
  • The LEDs require 5v and are powered off the Arduinos 5v pin. It's a fairy simple setup. Grd to grd pin, data to pin 6 and live to 5v
    – K20GH
    Jan 4, 2017 at 0:05
  • X number of LEDs time 60 mA > USB Amax. Jan 4, 2017 at 10:53

2 Answers 2

2

See Powering NeoPixels.

Each individual NeoPixel draws up to 60 milliamps at maximum brightness white (red + green + blue).

OK, so you have 144 LEDs.

#define NUM_LEDS 144

That means you need to allow for 8.64 amps to power them!

144 * 0.060 = 8.64

(This is a worst-case scenario, but you should probably allow for 2 amps at least).

As st2000 points out, the USB interface will provide 500 mA (0.5 amps). So you are possibly 8 amps short. You need to power the NeoPixels independently, not through the Arduino.

By powering them through the Arduino they are draining the current from the USB port so much that the over-current protection kicks in.

2
  • See my comment above. Your answer is theoretically correct, bit given that I can light the entire strip white and 100% brightness and run any FastLED without issue, it would disprove your theory on power consumption
    – K20GH
    Jan 4, 2017 at 7:55
  • 1
    I measured my 24-pixel strip using your sketch and it took 388 mA. Extrapolating to 144 pixels you get 144/24 * 388 which is 2.328 amps. You just can't get that from your USB supply! I note that you acknowledge here that "OK well power was definately the issue" so perhaps you can upvote the replies here that said so, and accept one of them.
    – Nick Gammon
    Jan 4, 2017 at 22:50
2

It is inferred from your question that the Arduino is getting powered through the USB port. As you say the Arduino appears "gone" from the computer when you light up too many LEDs.

All USB ports are only obliged to supply 500mA with out the USB Device (the Arduino) negotiating for more power from the USB Host. If the load goes beyond 500mA, the USB Host (the computer) can limit the power my reducing the voltage. At some point the Atmel processor on the Arduino will stop working.

There are many tutorial on how to use LED strips on the web. Most will indicate power from a larger than normal power supply is necessary. Also, that the LED strip power should be connected directly to an appropriately chosen power supply.

The following image from this web page illustrates this:

enter image description here

(Note: In this picture PIN 6 was chosen to communicate with the LED strip. Your specific application (program or sketch) may use a different pin. Also, realize that the power supply in the picture is wired to only power the LED strip. The Arduino still needs to be powered.)

3
  • You are correct for only fort the example above. I can quite happily make the entire strip white at 100% brightness or run any of the FastLED or Neopixel examples without an issue.
    – K20GH
    Jan 4, 2017 at 7:53
  • I'm trying this with my 5V PSU now, however I can't even get the LEDs to power on (even with just lighting 1 LED) The LED 5V goes to my PSU 5V+, GRD & Data to my arduino
    – K20GH
    Jan 4, 2017 at 9:19
  • What you say sound correct. If you are using 2 power supplies make sure their grounds are connected. I will add a link to a LED strip how to web page to my answer to help out.
    – st2000
    Jan 4, 2017 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.