LED strip not working - arduino

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.

Related

Running WS2812B strip on 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.

Fading Adafruit neopixels

I would like to create a motion-controlled night light for my corridor. For my project I have
Arduino Uno
PIR sensor
WS2812b RGBW light strip
5V power bank to drive the LEDs
After tinkering with my light strip, I have managed to get the LEDs to turn on and fade to a low Red color followed by a delay and finally fade back to a point where they turn off. As I understand the Neopixel library, maximum light intensity has a value of 255. However, as we're talking about night light, I estimate that a value of less than 20 is more than sufficient to illuminate my corridor. (I should note that I see many suggestions placing a resistor in front of the LED strip and a capacitor on the power supply - will this affect intensity?) As a consequence, the light does not fade/turn off smoothly, but instead go through the lower intensities before turning off - which is not very pleasant to look at... My question is therefore if you know of any way to create a more smooth fade? Below is my code so far. Note that I have had to insert specific lines at the bottom to actually turn off the leds, as setting the intensity to "0" apparently doesn't seem to do the trick - am I missing something here?
Ideally I would like to be able to dictate how long it takes for the LEDs to fade in/out.
Thanks in advance
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_COUNT 30 // How many NeoPixels are attached to the Arduino?
#define High_Intensity 20
#define Low_Intensity 1
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit... if you must, connect GND first.
void setup() {
strip.begin();
strip.show(); // initialize all pixels to "off"
}
void loop() {
brighten();
darken();
}
// 0 to 255
void brighten() {
uint16_t i, j;
for (j = Low_Intensity; j < High_Intensity; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, 0, 0);
}
strip.show();
delay(50);
}
delay(500);
}
// 255 to 0
void darken() {
Serial.begin(9600);
uint16_t i, j;
for (j = High_Intensity; j > 1; j--) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, 0, 0);
}
strip.show();
delay(100);
Serial.println(j);
}
// Turn leds back off
for(int i=0; i<60; i++) {
strip.setPixelColor(i, 0);
strip.show();}
delay(5000);
}
Regarding the off-topic part (I won't go into detail)
The capacitor between the power leads will protect the Neopixels controller from sudden voltage changes due to the fact that each pixel drives their leds with PWM.
The resistor terminates the communication lines which reduces reflections in the wires.
Both improve performance and reduce risk of damage to the pixels. Hence you should use them. Just make sure you use them on the correct pins. There's plenty of information online on how to properly control Neopixel strings.
(I should note that I see many suggestions placing a resistor in front
of the LED strip and a capacitor on the power supply - will this
affect intensity?)
This will not affect intensity! Intensity is only controlled by the pixels' pwm signal and the supplied current.
Programming-wise:
As I understand the Neopixel library, maximum light intensity has a
value of 255.
Yes brightness is controlled by 3 values, red, green and blue each ranging from 0 (off) to 255 (max brightness). It's the duty cycle of the led's color channel.
This gives you a brightness resolution of 256 values over the entire brightness range. (8 bit).
My question is therefore if you know of any way to create a more
smooth fade?
This causes a problem. If you want to operate in a lower brightness range you only have a very limited number of steps to fade through.
So what if we reduce the current that supplies the leds?
As control and led supply voltage are usually supplied through the same rail there is no way to dim the entire strip while keeping the 8-bit resolution.
To control the fading time alter the delay time between each value update. Keep in mind the limited dynamic and persistence of human vision. Any visible brightness change that happens < 30Hz will cause a noticable step.
Below is my code so far. Note that I have had to insert specific lines
at the bottom to actually turn off the leds, as setting the intensity
to "0" apparently doesn't seem to do the trick - am I missing
something here?
for (j = High_Intensity; j > 1; j--)
In the loop that darkens the strip you run the loop while j > 1. So the last brightness value you set is 2 which obviously isn't 0.
for (j = High_Intensity; j > -1; j--)
should do the trick.

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.

Arduino Project - LDR and ServoMotor Sync and Rotate

Im doing a home project just for fun and Im pretty new to the Arduino, but I do know the basics.
Im creating a automatic venetian blind where it will open when dark and close when bright.
So the slats of the venetian blinds will rotate to a open position when the light sensor detects darkness and rotate to a closed position when the light sensor detects light.
Im using:
arduino uno r3/
continuous servo motor /
led/
LDR (light sensor)/
10k resistor/
This code works for a standard servo motor. I wanted it to work with a continuous servo motor because you can "control it better" and its the one I have.
I guess I will need a if statement something like this:
if light sensor detects dark then rotate the servomotor a to a certain degree and then stop
and if light sensor detects light then rotate the servomotor to a certain degree and then stop.
#include <Servo.h>
Servo servo1;
int sensorPin = A0; // select the input pin for the ldr
int ledPin = 13;
unsigned int sensorValue = 0;
int servoPin = 9;
int pos = 0;
void setup()
{
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
servo1.attach(9);
pinMode(ledPin, OUTPUT);
}
void loop()
{
// For DEBUGGING - Print out our data, uncomment the lines below
Serial.print("Cell = "); // print the value (0 to 1024)
Serial.println(analogRead(sensorPin)); // print carriage return
pos = analogRead(sensorPin);
pos = constrain (pos, 0, 1023);
int servoPos = map(pos, 0, 1023, 255, 0);
int servoDegree = map(servoPos, 255, 0, 0, 179);
servo1.write(servoDegree);
Serial.print("Servo Degree = ");
Serial.println(servoDegree);
int val = analogRead(sensorPin);
val = constrain (val, 0, 1023);
int ledLevel = map(val, 0, 1023, 255, 0);
analogWrite (ledPin, ledLevel);
delay(50);
}
With continuous servo motors, you give up position information. (See this Polou page for details.) This means you won't know when the blinds have reached their open/closed positions unless you also add limit switches. If you go with the switches, then a continuous servo would work. A better solution might be a small gearhead stepper motor like this one from AdaFruit. They have torque but they are much slower than continuous servos.
Key thing is that you don't want to be energizing the motor continuously (which is how standard servos maintain position). That is wasteful and will burn out the motor in something like a blinds application, day in, day out. You want it to do the task and then in loop() wait until the state (light level in your app) has changed. So you would need to keep track of the last light level, then in loop() check if the current light level is different (and greater than some threshold you will have to determine through testing), then change the state of the blinds and store that last level.

Arduino RGB led-strip turns off at full intensity

I'm playing around with an Arduino Uno, and an RGB led-strip (Ikea Dioder 4 strips, only one is connected). Primary and secondary colors look fine when writing 255 to one or two colors. The problem is when I want white light (e.g. 255 on all three LEDs), then instead of becoming fully white, it just turns off.
I have an ethernet-shield connected to the Arduino, and a seperate 12V dc powersource. When I connect the power source to the Arduino, it works, but the regulator gets insanely hot (known issue). So I connect the LEDs to the 12V power source directly (they are rated at 12V, the Ikea one is also 12V). Only this causes the problem.
In the program below I can see it very clearly. The code should do the following: fade to red; fade to yellow; fade to white; repeat. The first two go fine, but when it's time to fade to white, it fades to black instead. It just turns off. And I have no idea why.
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
int color[] = {3, 5, 6};
int i = 0;
int j = 0;
void setup(){
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop(){
for(i=0;i<=2;i++)
{
for(j=0;j<=255;j++)
{
analogWrite(color[i],j);
delay(5);
}
}
delay(1000);
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
analogWrite(greenPin, 0);
}
Since it works fine then powered from Arduino, I guess this is hardware, not software problem. Arduino port providing around 40mA, while each colour of Dioder sync around 140mA. Do you use any amplification, like FET or ULN2003? Can you post your schematic?
The problem has been solved (I think) by connecting the GND for the IC and the (-) side of the adapter to the GND of the Arduino.

Resources