Arduino Due 4 LED Strips flickering.

Hi everyone,

I'm new to this Forum. I recently bought an Arduino Due to power my 4, 3.5m RGB LED strips I have at home. I connected my Arduino like on this wiring plan.(http://ikennd.ac/pictures/ArduinoDioderWiring.pdf) I then created a simple application that is changing the colors of all 4 strips all at once - it works well, but to one problem: The strips are flickering. It's not the case if I only power one strip. I use a standard 12V LED power supply that was shipped with my strips. There must be an wrong connection or something like that. Any suggestions what I can do?

Thanks in advance.

Hi binux, is this flickering random or regular?

Do you have a 0.1uF cap for each uln2003, close to each chip's power pins?

Paul

PaulRB:
Hi binux, is this flickering random or regular?

Do you have a 0.1uF cap for each uln2003, close to each chip's power pins?

Paul

It's regular. No I didn't. I only have the parts shown on the plan. You mean at PIN number 8?

Is usual to connect pin 9 of the ULN to the same power rail as used by the loads (yellow wire in your diagram). This important for reactive loads like relays, not really important for LEDs, but it wouldn't do any harm. If you did that, you could connect the caps across pins 8 & 9. Don't pin your hopes on this fixing the flickering, but worth a try.

If that doesn't help, I would look next at the power supply. What happens if you remove the Arduino and the ULNs and wire up the LED strips direct to the PSU?

Another thing to try would be to make a very simple sketch that does not use PWM, just sets the outputs connected to the ULN inputs to OUTPUT & HIGH. If that does not flicker, post your PWM sketch for review.

PaulRB:
Is usual to connect pin 9 of the ULN to the same power rail as used by the loads (yellow wire in your diagram). This important for reactive loads like relays, not really important for LEDs, but it wouldn’t do any harm. If you did that, you could connect the caps across pins 8 & 9. Don’t pin your hopes on this fixing the flickering, but worth a try.

If that doesn’t help, I would look next at the power supply. What happens if you remove the Arduino and the ULNs and wire up the LED strips direct to the PSU?

Another thing to try would be to make a very simple sketch that does not use PWM, just sets the outputs connected to the ULN inputs to OUTPUT & HIGH. If that does not flicker, post your PWM sketch for review.

Okay, tried it - didn’t work. Here’s my code. May look a bit messy, I didn’t finish it up yet. It converts RGB to HSV and back so I can set the color by setting the H value. Th function colorShift is called in loop which sets the color.

#define SIZE    255
#define DELAY    100
#define HUE_MAX  6.0
#define HUE_DELTA 0.01
//LED PINs
const int red1 = 2;
const int green1 = 3;
const int blue1 = 4;

const int red2 = 5;
const int green2 = 6;
const int blue2 = 7;

const int red3 = 8;
const int green3 = 9;
const int blue3 = 10;

const int red4 = 11;
const int green4 = 12;
const int blue4 = 13;
//Values needed for HSV
long rgb[3];
long rgbval, temp_value, rands;
float hue=0.0, saturation=1, value=1;
long bright[3] = { 107, 67, 256};

int memory = 0;
int strip = 1;

void setup() {
  // Initialize LEDs - code reworked. Once was a single Loop.
  pinMode(red1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(red3, OUTPUT);
  pinMode(red4, OUTPUT);
  
  pinMode(green1, OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(green3, OUTPUT);
  pinMode(green4, OUTPUT);
  
  pinMode(blue1, OUTPUT);
  pinMode(blue2, OUTPUT);
  pinMode(blue3, OUTPUT);
  pinMode(blue4, OUTPUT);
   
  analogWrite(red1, 0);
  analogWrite(red2, 0);
  analogWrite(red3, 0);
  analogWrite(red4, 0);  
  analogWrite(green1, 0);
  analogWrite(green3, 0);
  analogWrite(green2, 0);
  analogWrite(green4, 0);
  analogWrite(blue1, 0);
  analogWrite(blue2, 0);
  analogWrite(blue3, 0);
  analogWrite(blue4, 0);
}

void loop() {
  //changes color over time.
  colorShift();
}
//called from Loop function
void colorShift(){
  hue += HUE_DELTA;
  //switch to zero
  if (hue > HUE_MAX) {
    hue=0.0;
  }
  //write color
  setLEDs(hue, saturation, value);
  delay(20);
}

//Turns on all LEDs with value 
void setLEDs(float hue, float saturation, float value){
  rgbval=HSV_to_RGB(hue, saturation, value);
  rgb[0] = (rgbval & 0x00FF0000) >> 16; // there must be better ways
  rgb[1] = (rgbval & 0x0000FF00) >> 8;
  rgb[2] = rgbval & 0x000000FF;
  
    //rewritten -- once was a single loop
    analogWrite(red1, rgb[0] * bright[0]/256);
    analogWrite(red2, rgb[0] * bright[0]/256);
    analogWrite(red3, rgb[0] * bright[0]/256);
    analogWrite(red4, rgb[0] * bright[0]/256);  
    analogWrite(green1, rgb[1] * bright[1]/256);
    analogWrite(green2, rgb[1] * bright[1]/256);
    analogWrite(green3, rgb[1] * bright[1]/256);
    analogWrite(green4, rgb[1] * bright[1]/256);
    analogWrite(blue1, rgb[2] * bright[2]/256);
    analogWrite(blue2, rgb[2] * bright[2]/256);
    analogWrite(blue3, rgb[2] * bright[2]/256);
    analogWrite(blue4, rgb[2] * bright[2]/256);
}
//Converts HSV to RGB
long HSV_to_RGB( float h, float s, float v ) {
  // H is given on [0, 6]. S and V are given on [0, 1].
  // RGB is returned as a 24-bit long #rrggbb
  int i;
  float m, n, f;

  // not very elegant way of dealing with out of range: return black
  if ((s<0.0) || (s>1.0) || (v<0.0) || (v>1.0)) {
    return 0L;
  }

  if ((h < 0.0) || (h > 6.0)) {
    return long( v * 255 ) + long( v * 255 ) * 256 + long( v * 255 ) * 65536;
  }
  i = floor(h);
  f = h - i;
  if ( !(i&1) ) {
    f = 1 - f; // if i is even
  }
  m = v * (1 - s);
  n = v * (1 - s * f);
  switch (i) {
  case 6:
  case 0: 
    return long(v * 255 ) * 65536 + long( n * 255 ) * 256 + long( m * 255);
  case 1: 
    return long(n * 255 ) * 65536 + long( v * 255 ) * 256 + long( m * 255);
  case 2: 
    return long(m * 255 ) * 65536 + long( v * 255 ) * 256 + long( n * 255);
  case 3: 
    return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
  case 4: 
    return long(n * 255 ) * 65536 + long( m * 255 ) * 256 + long( v * 255);
  case 5: 
    return long(v * 255 ) * 65536 + long( m * 255 ) * 256 + long( n * 255);
  }
}

I tried to just put LEDs on HIGH and this didn’t flicker, but once I put the command in the loop section, it did.

Hmmm... it is quite complex for such a simple task. How much of it did you write yourself?

I suspect the flickering is due to precision limits in the floating maths or truncations in the integer maths somewhere there. Do you know what the purpose of the bright array is? What is the significance of the values assigned to it?

PaulRB:
Hmmm... it is quite complex for such a simple task. How much of it did you write yourself?

I suspect the flickering is due to precision limits in the floating maths or truncations in the integer maths somewhere there. Do you know what the purpose of the bright array is? What is the significance of the values assigned to it?

The code works for one led strip. I tried an easier approach and just put red color for all strips in loop but it still flickered. The have to RGB is copied the rest is my own :wink:
Bright arty had sense once. Due that I changed the code at the marked position.

binux:
The code works for one led strip.

Explain this further please. Post that sketch. Does it work for any of your 3 strips?

binux:
Bright arty had sense once. Due that I changed the code at the marked position.

Sorry, don't understand. What marked position are you referring to? The bright array is being used in your sketch.

I have used the following easy method for achieving a "rainbow" fading sequence before:

A "colour" int variable changes from 0 to 767, then immediately back to zero again, at a speed of your choice.

When colour is between 0 and 255, red = colour, blue = (255 - red) and green = 0
When colour is between 256 and 511, green = (colour - 256), red = (255 - green), and blue = 0
When colour is between, 512 and 767, blue = (colour - 512), green = (255 - blue) and red = 0

PaulRB:

binux:
The code works for one led strip.

Explain this further please. Post that sketch. Does it work for any of your 3 strips?

binux:
Bright arty had sense once. Due that I changed the code at the marked position.

Sorry, don't understand. What marked position are you referring to? The bright array is being used in your sketch.

I have used the following easy method for achieving a "rainbow" fading sequence before:

A "colour" int variable changes from 0 to 767, then immediately back to zero again, at a speed of your choice.

When colour is between 0 and 255, red = colour, blue = (255 - red) and green = 0
When colour is between 256 and 511, green = (colour - 256), red = (255 - green), and blue = 0
When colour is between, 512 and 767, blue = (colour - 512), green = (255 - blue) and red = 0

I exactly use this code, but only on one strip. No problemo, eveything works. When I use it on more than one it's flickering. Especially the strips with a higher pin number.

I got it. It was the bright array that was causing the flickering. Bright should set the brightness for all colors in the old code -- it was a loop at that time - then i changed it and didn't delete it. This was the trouble. Now it's working without any flickering thank you very much!

It turned out that I was too fast. LEDs are still flickering a little when it's changing from blue to red to orange. the slower I make it the stronger it is. I guess it has something to do with the HSV technique - I just don't know exactly what causes the problem.

Is this really "flickering" or are you simply noticing the individual steps in the fading? They are quite visible with 8 bit pwm for the low values, e.g. under 20. If so, you either live with it or find a way to achieve 10 or 12 bit pwm.

PaulRB:
Is this really "flickering" or are you simply noticing the individual steps in the fading? They are quite visible with 8 bit pwm for the low values, e.g. under 20. If so, you either live with it or find a way to achieve 10 or 12 bit pwm.

Well I figured out that the flickering is the strongest when I set the RGB to 127,127,127 --> middle PWM size? If I connected all LEDs to the same pins after the uln it wouldn't flicker at all, but since I want to be able to control them individually it's not possible to do so. I have another breadboard setup with some BD241C MOSFET in mind, but I would have to use one for each pin which is causing a much bigger circuit. I also reduced my code to a minimum (means I set the values directly in the setup function - no change in loop) and it still flickers. (therefore not caused by inaccurate float values) Maybe the analogWrite function is not properly working? I could create my own, since it's not flickering when the LEDs are on HIGH.

What if, using your simplified sketch, you connect some individal leds (with series resistors of course) direct to the Arduino pwm outputs. Can you see them flickering?

PaulRB:
What if, using your simplified sketch, you connect some individal leds (with series resistors of course) direct to the Arduino pwm outputs. Can you see them flickering?

I don't have single LEDs around here. Any other Idea?

No individual leds? You’ve never run the “blink led” sketch? You’ll be telling me next you don’t have a DMM either! Well, get a few single leds. Always a useful addition to your electronics toolbox! Don’t forget series resistors (~200R).

PaulRB:
No individual leds? You've never run the "blink led" sketch? You'll be telling me next you don't have a DMM either! Well, get a few single leds. Always a useful addition to your electronics toolbox! Don't forget series resistors (~200R).

Come on blink led sketch, I don't need an Arduino to make a blinking LED circuit :wink: I will detach some of some of circuits I made - at least I have all required resistors. I'll post an update once I've done it.

They don't flicker. Is it possible that my power supply doesn't have enough energy for the circuit? It's 12V and 2A, I have 4 LED strips with 3.5m -- 30 LEDs per metre. I ask that because I tried another power supply which only serves 1.2A and they really start to blink instead of flickering.

Hi, do you have a DMM to measure the output volts of your 12V supply.
Is it a regulated supply or a block that is rated to give 12V at 2Amps?

Tom....... :slight_smile:

TomGeorge:
Hi, do you have a DMM to measure the output volts of your 12V supply.
Is it a regulated supply or a block that is rated to give 12V at 2Amps?

Tom....... :slight_smile:

I have no DMM -- It's a block rated to give 12V and 5A. (I upgraded it didn't change anything)