Arduino RGB led-strip turns off at full intensity - arduino

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.

Related

Arduino analogWrite() between two pins only working in one direction

I have a set of leds that are setup every other led reversed so when I apply power one way light 1,3,5... light. Change power and 2,4,6... I'm trying to set the brightness using PWM on the digital pins. Here's my code:
unsigned long flashCount = 0;
bool bSwitch = true;
void setup()
{
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{
if((flashCount + 1000) < millis())
{
if(bSwitch)
{
analogWrite(6, 0);
analogWrite(7, 1);
bSwitch = false;
}
else
{
analogWrite(7, 0);
analogWrite(6, 1);
bSwitch = true;
}
flashCount = millis();
}
}
If I change analogWrite to 255 instead of 1, it will switch both sets of leds. If I change analogWrite to 127 or less, only one set will light. If I switch the led wires to the pins, the problem switches to the other set of lights.
The leds are like so:
GPIO pin 6 --------.-LED+.---.-LED+.---.-LED+.---.-LED+.---|
GPIO pin 7 ---.+LED-.---.+LED-.---.+LED-.---.+LED-.--------|
Change the connection of the LEDs to pins that both support PWM.
Not all pins support PWM. The analogWrite documentation specifies which pins depending on which board:
On most Arduino boards (those with the ATmega168 or ATmega328P), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.
The other factor is that analogWrite(255) and analogWrite(0) will revert to driving the output as a digital output. So writing 255 causes both pins to output (one as a digital output and the other in PWM mode). But writing 1 to 127 only causes the PWM capable pin to change.
From arduino's manpages:
Syntax
analogWrite(pin, value)
Parameters
pin: the pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int
Using an analogWrite with a value of 1 is essentially near-zero. 255 would be full voltage. You're attempting to use analogWrite() as if it was digitalWrite().
Consider using digital write instead in your code: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/
As for your LED's behavior, it seems like your circuit needs to be debugged as well: Your circuit will only allow current to flow when pin 7 is on. Diodes (Light Emitting Diodes) only allow current in one direction. If you're intending to have the LED's alternate, they should all be oriented with the positives pointing toward their GPIO pin and where they meet they should be grounded with a pull-down resistor.

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?

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!

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.

Resources