For a 3.7 Volt supply to RGB LEDs, the blue channels have a fairly high forward voltage (3.0 to 3.6 Volts per the datasheet), so using BJTs will leave very little or no voltage headroom for the current limiting resistor to regulate current.
The 2n3904 BJT shown, has a Vce(sat) of 0.2 Volts as per the datasheet, and will have a threshold pretty close to this figure, below which it will not conduct.
In other words, the design is likely to be marginal at best, or not work at all for the blue channel at least, depending on the actual Vf of each individual blue channel of the LEDs.
Instead, consider using inexpensive 3.3 Volt friendly, logic level MOSFETs such as the IRLML2502, available for as little as 24 cents each.
At a gate voltage of 2.5 Volts, the Rdson for the MOSFET above is 0.080 Ohms. With 100 mA (
20 mA * 5) passing through this, the resultant voltage drop at the MOSFET calculates to just
0.08 * 0.1 = 0.008 Volts = 8 milliVolts. More realistically, you might see a drop of as much as 0.01 Volts between Drain and Source.
Thus, there is nearly 0.1 Volts of headroom assured, say 0.5 Volts typical, for the blue channel LEDs. This is far better than what you would get from the BJT design.
In practice, since a MOSFET drain-to-source junction behaves essentially as an Ohmic path for current at a specified Vgs, there will be a linear reduction of voltage drop as the available voltage headroom reduces, so the blue part of the LEDs would continue to glow, if a little dimly, even at worst case. This is unlike the collector-emitter junction behavior of a BJT, which will essentially stop conducting entirely as you approach the marginal case.
Added advantages of the MOSFET approach:
- No careful calculation needed for the MCU output resistors: Just plug in a 100 Ohm resistor in series with the Gate, and a 10 kOhm resistor for pull-down from Gate to Source. Since the MOSFET gate is a voltage driven device not a current driven one, so no minimum base current required, nor any careful calculations.
- Less concern about heat at the transistors: The MOSFET with its 0.08 Ohm maximum on resistance, will generate negligible heat even at much higher than the 100 mA current currently being considered. A BJT will not have that advantage.
- No thermal runaway: MOSFETs have a negative temerature coefficient, current gets throttled as temperature rises.
- Only the LED current limiting resistors need to be recalculated if you choose to increase the supply voltage later, since 3.7 Volts makes things a bit iffy anyway.
The MOSFET switch circuit would look like this:
simulate this circuit – Schematic created using CircuitLab