Fading & Attaching x4 RGB 5mm LEDs

Hey Guys -

I'm working on a project for my 3 year old which I'm trying to add some RGB LEDs to and need some help with two topics, please.

First, I'm using a NodeMCU and have read that each GPIO provides 12Ma @ 3.3V. Given that the RGB LEDs are rated as (Red: DC 2.0 - 2.2V; Blue&Green: DC 3.0 - 3.2V (IF=20mA)), are common cathode, and obviously require 3 GPIOs each (1 per color). Given that I want all 4 of them to act the same, what would be the best way to wire these up? Should I split them up and drive two on 6 pins? Resistor(s) needed for red one? I've researched and seen a variety of answers. To note, the only other thing attached to the NodeMCU will be an MPU-6050.

The other issue is that I've been testing trying to get them to fade white on and off at the top of the loop while flashing a color in between for a few seconds depending on if statements. The only way I could get a smooth fade would be to use a library like RGB_LED. With it, I've been able to get a test LED to fade the way I want between different colors, but not white & off only. I've tried a number of combinations of the code without luck. Any suggestions?

Thanks, Guys!

If each LED has a forward current if 20mA, you can't drive any of them from a GPIO pin since they can only deliver 12mA. I have read that the pins can sink up to 20mA so you might go that way. Still, you will need 3 pins per LED and with 4 LEDs, you are using 12 pins. As for resistors, (3.3V - 2V) / 20mA = 65 ohms and your Blue and Green are already at Vcc.

Maybe try some Neopixels? or WS2812B GRB LEDs?

Those run at 5V so you have to deal with that vs. the 3.3V chip

Thanks for replies so far. Guess I'll use 12 pins to drive the 4 - should still have two left over for SCL/SDA so should be good. If anyone can advise on the fading part, I'd appreciate. Thanks!

Ahh, I see.

You'd have to post your code if you want help with the fading. Are you using that library? It looks pretty straight-forward

I guess you haven't figured out yet just how many useless pins a NodeMCU has!

I'm trying to think what the simplest option is. Unfortunately, common cathode LEDs was a bad choice. Common anode are easier to deal with, more and simpler circuit options.

You will need at least 0.5~1V more than the forward voltage of your LEDs, because of the series resistors. You can't drive a 3.2V led with 3.3V, because the resistor would only be dropping 0.1V. Remember, the 3.2V forward voltage is just a "typical" figure and will vary a little from led to led and will also vary a little with temperature and current.

For 12mA current, the resistor would need to be (3.3-3.2)/0.012=8.3 Ohms. If your LEDs happen to be a little lower than 3.2V or they drop to 3.1V when warned up, you will have (3.3-3.1)/8.3=24mA flowing and damage the output pins and even the LEDs. That's the problem with using such low value series resistors.

With a higher voltage, you can use higher series resistors, and variations in the forward voltage of your LEDs make only a small difference to the current.

So I would recommend driving your LEDs with 5V and series resistors around 100R for blue & green and 150R for red. But then you need circuits to enable your 3.3V output pins to control the 5V supply, which means something like transistors, and because your LEDs are common cathode, pnp transistors or p-channel mosfets.

Are you familar with I2C? In that case I suggest to have a look on the SX1509 which comes with up to 16 LED drivers and enables PWM, pulse, blink, breath,... with "simple" I2C commands. Sparkfun has a nice library for that IC.