RGB LED flickering

Most beginners forget to connect the ground of the 12V power supply to the ground of the arduino.

I use an Arduino "compatibel" to the Nano 328. I am using mosfets so the LEDs strip current does not flow over the arduino and the ground and the +12V supply are the same for the arduino and the LED Strip. The wiring is identical to the tutorial:Usage | RGB LED Strips | Adafruit Learning System

If you do it right with the right components you should not see any flicker.

Mike can you also tell me which are the right components?

The components mentioned in the artical and not a subistitute that you think might work.

Shouldn't the the PWM frequency be high enough so that i cant see the flickering?

Your eyes do get better at preceiving flickering at low brightness. What you observe could be due to that.

What do you actually mean by flickering?
Is it perceivable looking directly at the light?
Or is it that you want to see no flicker as you rapidly scan your eyes across the field of view that contains the lights?

Hi lukeskymuh, I believe I might be encountering the same issue as you. The flickering I encounter is when the leds are dimmed to a low pwm value, they flicker in a way a candle flame does right before it goes out. Not like a refresh rate problem. I thought it was my hardware but I realize now I am not encountering the problem when I set the pwm to a fixed value, or strobe it with a simple loop. Turns out, the only time I can get this flicker to happen is when running that color swirl code form adafruit which you linked to. We have different hardware setups, but we are using that same bit of code. Do you have the flicker when setting the pwm to a value of 10 or when doing a simple pwm increase loop on the leds?

-Sathi

Sathi:
Hi lukeskymuh, I believe I might be encountering the same issue as you. The flickering I encounter is when the leds are dimmed to a low pwm value, they flicker in a way a candle flame does right before it goes out. Not like a refresh rate problem. I thought it was my hardware but I realize now I am not encountering the problem when I set the pwm to a fixed value, or strobe it with a simple loop. Turns out, the only time I can get this flicker to happen is when running that color swirl code form adafruit which you linked to.

What TLC library is that using? It's definitely possible to cause flicker by not controlling the chip properly.

No where in the thread was the TLC mentioned, yet you guessed that I might be using it? I am indeed. Is this a known issue? When I get home I will check what version of the library I have. Thanks.

-Sathi

I am using the Tlc5940_r014_2 library. I am pretty sure it is the newest one from the google code page at:

http://code.google.com/p/tlc5940arduino/downloads/detail?name=Tlc5940_r014_2.zip&can=2&q=

Not sure what the deal is, but I can generate all sorts of weird artifacts based on different code parameters. If I increase
the pwm values at a slow rate, the leds increase in brightness in pulsating sort of pattern, like they are breathing. At faster speeds things look smooth. But I can't get it to fade slowly from one color to the next in a smooth manner. Especially at low
pwm values where they have that strange candle light like flicker. I'll avoid hijacking this guys thread and make a new topic on this I can't get it worked out. Thanks.

-Sathi

Know this is old but I thought I'd just chime in here as this was doing my head in!
I was seeing the exact same thing and no change in the code seemed to fix it.
It was barely noticeable on the red channel, but very noticeable on green and a bit less on blue.
Anyway, I was using a 12V 1A adapter and even though the strip i was using should have been drawing less than that, when I swapped it for a 6A unit, all flickering ceased.

Anyway, I was using a 12V 1A adapter and even though the strip i was using should have been drawing less than that, when I swapped it for a 6A unit, all flickering ceased.

That is probably because you did not have enough decoupling capacitors on your power supply. A couple of caps would have saved you from buying a 6A supply.

Grumpy_Mike:
That is probably because you did not have enough decoupling capacitors on your power supply. A couple of caps would have saved you from buying a 6A supply.

Seems I misread the current draw for the strips. With the 6A supply connected I measured 3A draw at %100 white. Stats were correct, I was just not accounting for the correct strip length.

3A from a 1A supply. Flickering should have been the least of my worries!

ok, sorry to rebump and old post but I also encountered this very issue and found it annoying enough to fight it tooth and nail...

I think I won :wink:

and the solution for me, was to force phase-correct PWM mode on timer0, based on this article: https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM

(I was using pins 5, 6, 9 on an ATmega328P, 5+6 being controlled by timer0)

of course, that means that milliseconds now last twice as long :wink: but I can live with that :wink:

maybe it will help someone who has the same kind of problem...

btw, the flickering does seem to depend on the current drawn (as it was way less noticeable and sometimes completely unnoticeable with a shorter strip) but even though my LED strip draws ~1.5Amp, even buying a 5Amp power supply for it didn't solve the issue before I tried the timer tweak.

best,
blue.

I'm a bit sorry as this thread is so old, but I'm also so near to the solution...

@blueshade how did you do it?
I've read the article, but I'm new to Arduino and honestly I haven't understood it 100%, I only got what the exact problem is. It would be very nice if you could provide the code which got it working for you.

Have a nice day,
maprambo

I got it!
I found this article: Arduino Playground - TimerPWMCheatsheet
I think it's a bit better explained here how you get to a solution.
So I just put this into setup:

void setup() {
   TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);
   // other setup stuff
}

and made this change in the wiring.c file (revert this change! only use it for this one sketch so that the millis and delay are correct here):

// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
// the overflow handler is called every 256 ticks.
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 510))

Does anyone have the correct way to set timer 1 and 2 to fast pwm, rather than timer 0 to phase correct?
I'm running 2 RGB strips, so I'm using all 6 PWM pins.
I've tried following other guides for this, but they all seem to assume you'd only want to set timer 1. My attempts to set timer 2 to anything else have it either not fix the problem, or it gets some massive deadspots for all values between about 50 to 225(I think its accidentally set to 16 bit mode). Timer 2 acts differently to timer 1, and I dont really know what I'm doing.
Setting timer 0 to phase correct PWN mode definitely solves my flicker problem, but I have a lot of code with some delicate delay interdependence, so I'd rather not have to adjust it all if I dont have to.

I think it is explained in this video: Why I’m switching over from the awesome Arduino IDE to Atmel Studio

Old thread, but I thought this may be helpful for those new to this (like me).

I am driving a single 16ft led rgb strip using IRLB8721 N channel mosfet's, with a 12v 5a power supply connected to the barrel jack on the uno. The VIN is connected to the +12v lead on the rgb strip. This was following the adafruit example here: Usage | RGB LED Strips | Adafruit Learning System

I was experiencing PWM led rgb flicker as well, once the duty cycle wasn't 100%. As other's have mentioned, different pins have a different frequency depending on their timer.

On Arduino Uno ATmega328P, the frequencies are defined in the previously mentioned article, Arduino Playground - TimerPWMCheatsheet.

I was originally using pin's 3 (red),5 (green) and 6 (blue) and noticed the flicker almost immediately when changing values.

The solution is very simple if you only need to drive one strip (3 pins). In my case, choosing pins with the same frequency works fine. e.g., 3, 9, 10 which all have the same frequency of 490.2. Dimming, fading, etc., all works great.

Hope this helps!