RGB with Tlc5940

Hi everyone,

I want to start playing with LED's and potentially build an RGB cube of some description. So i made a small shield for my Arduino UNO with a Tlc5940 to drive 5 RGB LED's.

I have it all up and running but with one sketch, i get a lot of flicker of the LED's. Its supposed to light all LED's bright white and scroll a blue LED along the line of RGB's. It's nice and stable for a few seconds then starts flickering. The weird thing is, when i touch certain parts of the UNO, mainly the traces on the back to digital pin0 through to roughly pin5, the flickering gets worse. When i take my hand away, the flickering goes away for a bit then returns after a few seconds.

Other sketch's don't have any flickering at all and reducing the brightness of the LED's through PWM doesn't help.

Ive read in multiple places about using decoupling capacitors on the Tlc5940 with varying values suggested. I've mainly tried 0.1uf and 47 uf or a combination of the 2 as suggested in different posts but it doesn't go away.

I'm fairly certain it's not the code as this shouldn't be affected by me touching the board.

Does anyone have any suggestions on how to stop the flickering?

I've included the schematic and code as well.


#include "Tlc5940.h"

byte val1 = -3;
byte i = 0;
int val;

void setup()

void loop()
    if(i > val1 && i < val1 + 3){
      val = 0;
    val = 500;
    Tlc.set(i, val);
    Serial.print("I = ");
  Serial.print("     Val = ");
  Serial.print("     Val1 = ");
  if(i == 14){
    i = 0;
    val1 += 3;
  if(val1 == 18){
    val1 = 0;

Where's the schematic?
You should make a branch version of the code to just turn all the LEDs on. So you can be sure you're only troubleshooting hardware.

Try removing the serial print statements (comment them out).

Oops sorry. Not sure why it didnt attach. Will post the shematic when i get home from work.

I have some more code which turns all LEDS on full brightness with no issue. Another that cycles all LEDs through a range of colours with no problems either. It only happens when i have the scrolling blue LED. And only sometimes! Not always!

I have tried commenting out the Serial print statements as well but that didnt help. Im sure its something to do with the power and cycling of the LEDs. I even tried an external 5.5v/3a3A power supply with no joy.


What's the value of your current limiting resistor on the TLC5940 ?

The current limiting resistor is 2x1k in series. I didn't have any 2k resistors.

Here is the circuit schematic.

RGB shield.pdf (30.1 KB)

If that was the schematic then it would not work as all the LEDs are the wrong way round.

You have decoupling on the power supply to the chip but what value is it. You should use a 0.1uF capacitor but much more importantly it should be a ceramic type of capacitor and the lead between the capacitor and the chip should be as short as possible.
You might have bad connections if you are using a solderless bread board.

Thanks grumpy Mike.

I never even noticed the backwards LED's in the schematic. Fortunately I'm using 5050 SMD LED's and had a go at printing my first circuit board. Luckily the SMD pads are not polarity specific so when i soldered the LED's to the board i made sure they were correctly oriented on the pad.

As for the cap, Ive tried a few different values which is why i haven't included it on the schematic. I've tried the most common values, namely 0.1 uf ceramic and 47uf caps which were suggested on other forums as well as a few lucky dip values. I've checked all connections with a continuity tester and they appear to be sound.

I'm wondering, is the arduino on board 5v supply able to power 15 LED's? at 20mA per LED, with all on they would be drawing 300mA. With pulsing the LED's to scroll the blue light could this be an issue? Although i tried an external supply, the LED's were still powered from the Arduinos 5v rail. Perhaps i should power them from the Vin pin with the 5v external power supply?

So your circuit is not breadboarded, correct ?

Thats correct.

Its on my first DIY printed PCB. I've had to modify it a bit after soldering but all the solder joints are secure. I changed the power supply from the Vin to the 5v supply just in case i used it with, say, a 12v power supply. I didn't want to blow the LED's. Now i wonder if the supply is the problem.

I've run plenty of different programs on it with no problems. It's only the one program that only flickers sometimes. I'm still thinking it's a power supply problem to the chip.

I may try printing a new PCB in a few days and trying it again, just in case.

I would go back and start looking at the code again.

OK so,

This is doing some really weird stuff. I've tried writing some code to simply turn on all the leds in a different way to all my other attempts.

It certainly turned all 5 RGB LEDS on (all 5 white). However, the flicker was still there. I figured, i wonder if it's because it's constantly updating the Tlc within the loop, even though the LED's are already on? So i added "counter".

The idea was, it would run the loop once and turn all the LED's on then change "counter" to 1. The Tlc.update() function would be within an "if" statement relying on "counter" equalling 0. This should cause the Tlc to only update once, leaving the LED's on.

Here's the weird thing. I didn't get a chance to add the "if" statement and only added counter as in the code at the bottom of this post. I ran it, and the flickering was gone! I thought that was really strange so i commented "counter" out and the flickering was back. What the heck? The counter isn't even doing anything in the code! The Tlc is still being updated every time the loop is run.

How on Earth does commenting out "counter" in the loop make it flicker?

Man, I'm stumped!

So i tried to see what "counter" was doing. I added "Serial.println(counter);" directly after "Tlc.update().

Now i could comment out "counter" or leave it in. Either way the flickering was gone. By adding the Serial.println, counter didn't matter. Next i commented out the Serial.println and the flickering was back.

I am so confused!

How does adding or removing a useless/unused variable like counter, or a Serial.print command cause it to flicker?

#include "Tlc5940.h"

byte i;
byte j;
byte counter = 0;

void setup() {

void loop() {
  if (j == 3) {
    j = 0;
    i += 3;
    if (i == 15) {
      i = 0;
      //counter = 1;
    Tlc.set(i + j, 500);

You're probably not allowed to send commands to tlc so often. Add some delay time to the loop to slow things down.

How on Earth does commenting out "counter" in the loop make it flicker?

The extra work in adjusting the counter variable takes time. This was adding a delay into your loop and preventing you from updating the TLC too often.

Thanks guys.

Ill give that a go shortly. Hopefully this is the solution i was looking for.