Flickering leds problem

Hi,

I made a Philips Ambilight clone using BobLight (google it if interested) and Arduino Mega.
The system is now up and works nicely. I have only one problem:
The leds are flickering a bit. They are controlled with ULN2003 ic and the ics are feeded with arduinos pwms.
I know that the analog write values that I write in the loop are stable but for some reason leds are flickering noticably.

My questions are:
Do you have an idea what is causing this?
Is there an easy solution to somehow even out / filter the current to the leds with some electronic component (capacitor, resistor, etc..)?

Thanks in advance
-orbitrek

There are many reasons that might cause flickering. However without a schematic drawing and posting your code it's nearly impossible to try and guess at what might be the cause(s).

Lefty

Hi,
Thanks for the reply.
My schematic is dead simple. It is nicely described in the picture in this thread (see a post by "Makkan").
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236091181

This is the code: (which is also quite simple)

// Declare variables for pin numbering
int r1Pin = 9;
int r2Pin = 2;
int r3Pin = 5;

int g1Pin = 10;
int g2Pin = 3;
int g3Pin = 6;

int b1Pin = 11;
int b2Pin = 4;
int b3Pin = 7;

// Declare variables for serial data read
// R1R2R3G1G2G3B1B2B3
int RR1 = 50;
int RR2 = 50;
int RR3 = 50;
int GG1 = 50;
int GG2 = 50;
int GG3 = 50;
int BB1 = 50;
int BB2 = 50;
int BB3 = 50;

void setup()
{
  // Set pins for data output
  pinMode(r1Pin, OUTPUT);  
  pinMode(r2Pin, OUTPUT);
  pinMode(r3Pin, OUTPUT);  

  pinMode(g1Pin, OUTPUT);  
  pinMode(g2Pin, OUTPUT);
  pinMode(g3Pin, OUTPUT); 
 
  pinMode(b1Pin, OUTPUT);  
  pinMode(b2Pin, OUTPUT);
  pinMode(b3Pin, OUTPUT); 
 
  // open serial port
  Serial.begin(9600);
}

void loop()
{
    // read data from serial (MoMoLight-"protocol")
    while(true){
      if (Serial.available() > 8) {
	RR1 = Serial.read();
	RR2 = Serial.read();    
	RR3 = Serial.read();
	GG1 = Serial.read();
	GG2 = Serial.read();
	GG3 = Serial.read();
	BB1 = Serial.read();
	BB2 = Serial.read();
	BB3 = Serial.read();
      }
    
    // Write values to PWM ports (values = 0...255)
    analogWrite(r1Pin, RR1); 
    analogWrite(r2Pin, RR2);
    analogWrite(r3Pin, RR3);
    
    analogWrite(g1Pin, GG1); 
    analogWrite(g2Pin, GG2);
    analogWrite(g3Pin, GG3);
    
    analogWrite(b1Pin, BB1); 
    analogWrite(b2Pin, BB2);
    analogWrite(b3Pin, BB3);
}
}

If you have any ideas, I'd be glad to hear them. Thank you.

EDIT: And I noticed it is more clearly visible with some specific shades.

The thread you reference doesn't so a schematic with ULN2003s in it. You'll need to provide an actual schematic of your circuit.

Probably not related to the flickering you are seeing, but there is no need for the "while(true)" loop. loop() already does this for you.

Is it this one?

If so the first thing to note is that you are over driving that chip. You can't have 1.2A being switched on at the same time due to the thermal dissipation limit of the chip. See :- Power Examples

Next flickering covers a wide variety of behavior, can you be more specific?

To eliminate a software problem, write a sketch that doesn't read anything from the input and just changes the intensity of each lamp on an algorithm of some sort. Like incrementing one light every 100mS, it's OK to use delay for testing.

Yep, That's the one. Thanks for the heat dissapation link.
The led strip is driving 180 mAmps per channel at max and it is rarely reached. There's max 5 channels per chip. So 0,9 amps is the max.

How would I explain the flickering. It is some (high frequency) changes in the intensity of the light. So that light is not stable and calm and steady. It is actually doing it really little, but enough to catch the eye.

I need to do some testing without serial reading.

There's max 5 channels per chip. So 0,9 amps is the max.

So too much then.

It is some (high frequency) changes in the intensity of the light

It is the high frequency that is the important factor. When you switch a lot of current you can get instability in a circuit, try a bit of decoupling:- De-coupling

I need to do some testing without serial reading.

Yes you need to see if you are telling the software to make it flicker first.