RGB LED connected to 3 GPIO pins of microcontroller - red doesn't turn off all the way

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
Hey guys,
I am using a common anode RGB led, I have +5 volts going in to the common anode, then I have each cathode going through a 1K resister then to a GPIO pin of a 3.3V microcontroller. Ground is pulsed on the GPIOs to create a PWM signal to get the desired colors, and it works great.... with the exception that the red channel has a very dim glow when completely off (off being a high on the GPIO of 3.3V)

I believe it has to do with the voltage drop of the red led being different than the blue and green? When the red is off, there is 5V on the anode, 1K resistor, then 3.3V on the cathode.
You might wonder why I don't just use 3.3V and lower resistor values? This is because an old design is being retrofitted with a different LED. Another solution would be for me to have the GPIO drive a transistor/mosfet, which would pulse the ground for the LEDs, but this is not an easy change at the moment.

Something I tried was making the GPIO an input when I want it off completely, and this does work, but this is a hack and will only solve the problem if I want it off 100%.

I also noticed that not all brands of RGB LEDs do this, only certain ones...

Is there an easy solution to this? Is it as easy as just using a different resistor value for the red channel?

Here is the voltage drops for the LEDs I'm using:
 

dl324

Joined Mar 30, 2015
16,839
When the GPIO is HIGH, it's at 3.3V. That appears to be sufficient to light the red LED, but not the others.

If you want the LED to be off, you need to use a transistor to switch (at least) the red LED. Or, maybe a level shifter.

Another thing to consider is that when your GPIO's are HIGH, you're forcing current into those pins from your 5V supply. All logic is going to have a limit to the amount of current you can safely force into an output before something bad happens (electromigration and/or latch up).
 

dl324

Joined Mar 30, 2015
16,839
If you use transistors (e.g. MOSFETs) you have to change the polarity of your GPIO signals. With level shifters, you don't.

Here's a schematic from Sparkfun:
upload_2017-2-25_10-5-41.png

And, since I used their schematic, here's the URL to their product:
https://www.sparkfun.com/products/12009

But you can buy them from AliExpress for a tenth of the price...

They come 4 to a board:
upload_2017-2-25_10-7-17.png
 

LesJones

Joined Jan 8, 2017
4,174
If you are using a 3.3 volt micro controller and the LED anodes are connected to 5 volts then when the GPIO pins are high they will be at 3.3 volts so you will still have 1.7 volts across the LEDs (When you are expecting them to be off.) A red LED requires the lowest voltage so it is just starting to conduct with 1.7 volts across it which causes it to low dimly. The other LED require more than 1.7 volts to make them conduct so they don't glow. I think the figure on the packet of 2.0 volts for red LEDs is wrong. From memory it is normaly quoted at 1.8 volts. Adding a silicon diode in series with the red LEDs should solve the problem as it will give another 0.7 volts volt drop. (It is not realy good practice to use the output of a 3.3 volt micro to pull down loads connected to 5 volts.)

Les.
 
Last edited:

dl324

Joined Mar 30, 2015
16,839
Adding a silicon diode in series with the red LEDs should solve the problem as it will give another 0.7 volts volt drop.
That will still force current into the GPIO when it's HIGH. That current must be limited to a value that will avoid electromigration or latch up.
 

DickCappels

Joined Aug 21, 2008
10,153
You did not mention what microcontroller you are using. PIC?

Yes, I think you understand correctly. It is probably the difference between the +5V supply and the voltage on your GPIO pin that is causing only the red LED to glow when it is supposed to be off.

Two simple solutions come to mind:

From your description the residual current through the red LED is very low, so it should not take much current to reduce the voltage across the LED. As a simple fix I would try putting a small pull-up resistor to pull the cathode of the red LED up a little. Maybe 1k, maybe a larger resistor would work too.

If you put a diode in series with the LED it will reduce the voltage across the LED and that will probably work well too.
 

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
Thanks for all of the responses!

You did not mention what microcontroller you are using. PIC?

Yes, I think you understand correctly. It is probably the difference between the +5V supply and the voltage on your GPIO pin that is causing only the red LED to glow when it is supposed to be off.

Two simple solutions come to mind:

From your description the residual current through the red LED is very low, so it should not take much current to reduce the voltage across the LED. As a simple fix I would try putting a small pull-up resistor to pull the cathode of the red LED up a little. Maybe 1k, maybe a larger resistor would work too.

If you put a diode in series with the LED it will reduce the voltage across the LED and that will probably work well too.
I put a 4148 diode in series with the LED, so it goes like this: 5V -> LED Anode -> LED Cathode -> Resistor -> 4148 Diode -> GPIO pin on microcontroller, and this looks to have solved the problem. The LED (red channel) is still nice and bright, and it turns off completely.

The reason why I chose the 4148 is because I am already using a couple of them on the board anyways, and they are cheap.

And I am under the impression it really doesn't matter where I put the diode, is this correct? Really the only option is before or after the resistor.
 

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
You might be able to dodge extra work by setting the pin to 'input' when you need it to be off
Its funny you mentioned that... this was actually the first thing we tried, and it did actually work. It ended up having too many side effects with the firmware and the underlying code that we figured we should correct it with a hardware fix. Thanks for the info!
 
Top