Hey guys!
I thought it would be really cool to have a LED-Strip under my bed and I've stumbled across one oft the many Arduino-Individual-Controllable-LED-Strip-Projects out there and decided to give it a go myself. I ordered an Arduino Uno as well as a WS2812b LED-Strip as well as some jumper cables. I decided to use CLion instead of the Arduino IDE as I am very familiar with IntelliJ. I then used the PlatformIO IntelliJ plugin to get the FastLED working. Up to this point everything went smooth and my Hello-World-Programs worked like charm.
Problem:
I'm on MacOS so when I plug the Arduino to my USB-Hub (where 2 other Monitors as well as Mouse and Keyboard are hooked up as well) it won't work as then the Hub draws to much power from the PC and the PC just shuts down the USB-Port. So instead of plugging the LED-Strip into 5V (as intended) I plug the LED-Strip in 3.3V on the Arduino so it doesn't draw that much power.
As I decided to test the program with an external power source (instead of the USB-Hub on my MacBook) I noticed something very strange:
The program is behaving as expected as long as the strip is connected to 3.3V. But once I use 5V instead of 3.3V the program runs for a few seconds, then the LEDs won't update anymore. When I unplug the 5V connection from the Arduino to the LED-Strip it's working again, but only for a few seconds, then it will freeze again. This bothers me as, well, I'd like to run the RGB-Strip using 5V as this is brighter.
Any idea how to fix this?
I've tried different power bricks, but I only have one Arduino, one LED-Strip and 3 jumper cables.
tl, dr: Program works when Strip is plugged into 3.3V but stops after a few seconds when plugged into 5V (Strip is rated for 5V)
platformio.ini
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps_external =
FastLED
platform_packages =
; use GCC AVR 7.3.0+
toolchain-atmelavr@>=1.70300.0
main.cpp
#include <Arduino.h>
#include <FastLED.h>
#define DATA_PIN 3 // ID of the PIN the LED-Strip is connected to
#define LED_COUNT 90 // Amount of LEDs on the LED-Strip
#define BRIGHTNESS 255 // Brightness from 0 to 255
#define DELAY 100 // Delay between LED updates in ms
CRGB led_strip[LED_COUNT]; // Initializing the LED-Strip
int currentStart = 0;
bool isInRange(int number, int lowerBound, int upperBound);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
CFastLED::addLeds<NEOPIXEL, DATA_PIN>(led_strip, LED_COUNT); // Adding the LEDs
FastLED.setBrightness(BRIGHTNESS); // Setting the brightness
}
/*
* Loops: GREEN BLUE RED
* As we have 90 LEDs we will have 30 GREEN, 30 BLUE and 30 RED
*/
void loop() {
for (int currentLEDID = 0; currentLEDID < LED_COUNT; currentLEDID++) {
int currentOffset = (currentStart + currentLEDID) % LED_COUNT;
// Setting the color of the current LED
if (isInRange(currentOffset, 0, 9)
|| isInRange(currentOffset, 20, 29)
|| isInRange(currentOffset, 50, 59)) {
led_strip[currentLEDID] = CRGB::Green;
} else if (isInRange(currentOffset, 10, 19)
|| isInRange(currentOffset, 30, 39)
|| isInRange(currentOffset, 60, 69)) {
led_strip[currentLEDID] = CRGB::Blue;
} else {
led_strip[currentLEDID] = CRGB::Red;
}
}
if(++currentStart >=LED_COUNT - 1) currentStart = 0;
FastLED.show();
delay(DELAY);
}
bool isInRange(int number, int lowerBound, int upperBound) {
return number >= lowerBound && number <= upperBound;
}
main.cpp (1.61 KB)