Running WS2812B strip on arduino - arduino

I purchased a 5 meter strip of WS2812B LEDs to be used in conjunction with a motion detector (WS2812B 5 Pins RGBW RGBWW 4 IN 1 LED Strip Light Non-Waterproof DC5V).
The strips are hooked up to a 5V power supply (USB powerbank) and GND/5V/signal on pin 6 on an arduino UNO.
I should note that I so far have not cut the LED strip, so all 5 meters are intact.
I've tried getting the LEDs to emit simple colors using the FASTLED library using the code below. The Blue/blue/blue combination results in the colors Blue/Red/Green on LEDs 0-2
Changing to Red/Red/Red produces Yellow-ish/blue/off
Changing to Green/Green/Green produces the colors Red/lightgreen-ish/off
I've tried shifting from RGB to RBG color scheme to no avail
I don't have much information on the LED strip apart from what I have already provided you with
Can you give me any ideas on how to proceed?
#include "FastLED.h"
#define NUM_LEDS 5
#define DATA_PIN 6
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup()
{
//FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // for GRB LEDs
}
void loop()
{
leds[0] = CRGB::Blue;
leds[1] = CRGB::Blue;
leds[2] = CRGB::Blue;
FastLED.show();
delay(500);

This might not be the exact answer you are looking for, but I’d suggest using the Adafruit_Neopixel.h library for your LED’s. Just did a Projekt with that library and the exact LED strip you are using and it is working great so far.
#include "Adafruit_NeoPixel.h"`
#define LED_PIN 6
#define LED_COUNT 60
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int red = 100;
int green = 0;
int blue = 0;
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP}
}
void loop() {
for (i=0; i<LED_COUNT; i++){
strip.setPixelColor(i, strip.Color(Red, Green, Blue));
strip.show();
}
}
This should make 60 LED’s red. I’ve also got an LED Project on my GitHub page if you want to look that up. If the code above still doesn’t work I assume your wiring is wrong. I power my chip and LEDs off a power supple and also use the ground of the power supply.

Related

WS2812 LED light strips behaving strange

I had a long strip of WS2812 lights (300 LEDs) and had some code that was working completely fine. I decided to cut the strip so it would be the length of my desk but now the lights are acting strange and not following my code at all. I modified the code so it would work with the new length but now it doesn't work. I'm not sure if this is a hardware or software issue so I'll share the code I used and we can narrow it down from there. I simplified the code to light up just one LED but all the LEDs light up and are random colors which I have not had happen before. Here is the code:
#include <FastLED.h>
#define NUM_LEDS 10
#define LED_PIN 6
CRGB led[NUM_LEDS];
void setup() {
delay(100);
FastLED.addLeds<WS2812, LED_PIN>(led, NUM_LEDS);
}
void loop() {
led[0] = CHSV(100, 255, 255);
FastLED.show();
}
Let me know if there is more information you need and I will be happy to provide, thanks!

LED strip not working

we are still having trouble with our LED strip. We fixed the library issue, and are now trying to program the LED's but have run into a few issues.
1) First of all, our LED strip does not consistently light up. We are using a 12v battery and everything is wired correctly, but how the LED's appear is very inconsistent. Not all of them light up, they are all different colors, and are all of varying brightness. We have tried to resolve this by just powering it with the battery, using our arduino as a power supply, and added a 1000uf capacitor to make sure the strip doesnt get a surge of power and short the strip. Our code is this:
/* Arduino Tutorial - How to use an RGB LED Strip
Dev: Michalis Vasilakis // Date 3/6/2016 // Ver 1.0
Info: www.ardumotive.com */
//Library
#include <Adafruit_NeoPixel.h>
//Constants
const int dinPin = 4; // Din pin to Arduino pin 4
const int numOfLeds = 10; // Number of leds
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numOfLeds, dinPin, NEO_GRB + NEO_KHZ800);
// Color takes RGB values, from 0,0,0 up to 255,255,255
// e.g. White = (255,255,255), Red = (255,0,0);
int red = 255; //Value from 0(led-off) to 255().
int green = 0;
int blue = 0;
void setup() {
pixels.begin(); // Initializes the NeoPixel library
pixels.setBrightness(100); // Value from 0 to 100%
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<numOfLeds;i++){
pixels.setPixelColor(i, pixels.Color(red,green,blue));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(10); // Delay for a period of time to change the next led
}
}
We are trying to set all the LED's to red just to test the code, but nothing is working. Has anyone experienced this before or has any idea of what is not working?
99% of the time this happens when you haven't tied the ground of the LED strip to the ground of the Arduino and the ground of the power supply.

Arduino keeps crashing

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.
Also. If I plug the LED into the 3.3v pin, the animations works just fine, but the LED flashes black and doesn't complete the Blue part.
I never used the NeoPixels, so I'm not really sure about this, but I'm pretty confident these will solve your problem.
First of all, your program. I don't think it is doing what you think it should do. Try with this loop, instead:
void loop()
{
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(100);
for(int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Black;
FastLED.show();
delay(100);
leds[dot] = CRGB::Blue;
FastLED.show();
delay(100);
leds[dot] = CRGB::Red;
FastLED.show();
delay(100);
}
}
and remove the SetAll function, since it is useless.
Try this code with NUM_LEDS set to 5, and it should work.
Now the main problem: are you really using 144 leds powered by the USB? I suggest you to read this link about powering the neopixels. Particularly the part stating that at full brightness each neopixel draws 60mA. Doing the math, 144 neopixels draw at most 8.64A, so you need a 5V 10A power supply to power them all! a USB with 5V 0.5A will just shut itself down when you try to turn them on, thus giving you strange behaviors.
So lower the number of leds you are using (7 at most), or use an external power supply. And by external I do not mean use the barrel jack on the arduino, but connect a 5V 10A (or more amps) to the neopixel strip, then the ground and data wire to the arduino (not the +5v) and power the arduino through the usb port: it should work.
UPDATE:
According to the chat with the author, the problem was indeed the power supply
The datasheet from adafruit https://cdn-shop.adafruit.com/datasheets/WS2812.pdf says that you need a power supply between 6v and 7v but USB cannot provide more than 5v, I am guessing the arduino crashes because it cannot find enough power.
Can you try using an external power supply?

How to solve flickering WS2812?

I have a problem with flickering neopixel leds. I'm using a setup of 6 strips of 8xWS2812 5050 leds. I've connected these to a 5v power supply (USB charger) and an Arduino Uno running the Neopixel simple example code:
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 48
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 50; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(200,200,200)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
I've connected a 500uf 10v capacitor between the 5v and the gnd. And a 470 ohm resister between the arduino and the datapin.
I've noticed that the leds also flicker when the leds are on and the datapin is disconnected. The flickering is subtle, but annoying.
I've also tried an alternative power supply. For this I used a adjustable lab power supply. But the same problem persists.
I have to use these leds for a project that I need to finish tomorrow. (I know i should have done this earlier) Is there anyone who could offer me some help? I could really use some.
EDIT: The flickering had to do with the quality of the leds. These weren't real neopixels, instead I received some bad fake ones.

2 Pin RGB LED on an Arduino

I'm having some trouble setting up my RGB led. It's not common anode, so it only has 2 pins. Not 4. I can't seem to set the led up to change color. It will only blink red. I want the led to cycle through colors. Thanks for Helping!
int led1 = 2; //Don't worry about the other led variables, they work
int led2 = 7;
int led3 = 9;
int led4 = 12;
int led5 = 13;
int redPin = 5;int greenPin = 4;
int bluePin = 3;
//#define COMMON_ANODE
void setup(){
pinMode(led1, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
void loop(){
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
void setColor(int red, int green, int blue){
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
First of all this is not a software question.
When it comes to your problem, 2 pinned LEDs don't work the way 4 pinned ones work. If you are using an LED with 2 pins, you give them a voltage and wait for them to change their color with time.
However, you can change their 'Color changing time' applying PWM to it's Vcc pin. But on the other hand it makes it illuminate less.
Since you have a slow color changer you cannot control the timing through PWM. PWM is going to turn the LED on then off at a high rate. The color changing circuit in those 2 pin slow/fast color changer LEDs turns on when you apply voltage. As long as power is applied the program runs. When you turn it off and then back on (unless it is storing internal data) it will reset and start from the beginning of its programmed cycle.
Try this little experiment: Turn the LED on and wait 5 seconds. Take note of the color pattern. Turn it off and wait 2 seconds. Then turn it on again.
If it the color pattern starts over, then that LED "forgets" where it was and is reset every time power is applied.
If it continues where it left off (which I highly doubt), then it has internal NV memory and you might be able to control the changing speed but only in making it slower.
If after 5 seconds that LED never changes, I would have to say that it is a plain single color LED. To see if it is a Bi-Color type, try reversing the polarity. If you get another color, you have I Forward-Reverse Bi-Color LED. If not, you have a plain LED.
Hope that helps!

Resources