We would like to connect the 3-color LED module (KY-009) to the GPIO pins of Raspberry Pi 3. We are going to use the {green, blue} LEDs only (5050 SMD LED) of the module. Because

  • the LEDs require high forward voltage V_f > 2.75 V ([ref1]), which is at the limits of the GPIO pins' output V_OH > 2.90 V ([ref2]);
  • the LEDs draw large forward current I_f reaching up to 100 mA ([ref1]), while GPIO pins can't source more than 16 mA per pin & 50 mA combined ([ref2]),

we think of using this circuit ([ref3]): KY-009 Raspberry Pi interfacing circuit

Problem is, a voltage drop of (5−V_C) V across the LED load could exceed the maximum rating of the load V_f_max = 3.40 V ([ref1]).

Could adding resistance R_x before the load help? If so, how can we calculate its value?

More generally, is this circuit appropriate to use? — we're afraid of damaging the Raspberry Pi GPIO pins & are beginners in Electronics.

  • 2
    \$\begingroup\$ Did you read the bit in the datasheet that says: "You need to use resistors to prevent burnout."? On top of that, it looks like these have all their cathodes connected together so need to be driven by high sided drivers. I don't think the 2N3904 is at all suitable for this. \$\endgroup\$
    – DiBosco
    Dec 11, 2017 at 12:24
  • \$\begingroup\$ The datasheet you linked to for 5050 SMD LEDs is for individual colour LEDs. You would be better off looking at a datasheet for a 5050 RGB LED. You would be even better off by reading the datasheet for the KY-009 that you linked to. \$\endgroup\$ Dec 11, 2017 at 12:58

2 Answers 2


Why not save yourself some trouble and use an RGB LED driver? You could connect multiple ones to your I2C port or even bitbang over gpio. Something like the LP3944 or the LP5521

The LP3994 has eight channels and handles the current control for you. You can even DIM over I2C. They make a wide variety of these things, some with integrated boosters, controllers, etc.

enter image description here

  • \$\begingroup\$ It appears that the OP has a common-cathode device, so only the LP5521 from those suggestions would work. \$\endgroup\$ Dec 12, 2017 at 13:46

Here's an example solution that is based upon your schematic diagram. Perform these steps for each LED color—i.e., perform these steps for the red LED, then perform these steps again for the green LED, and again for the blue LED.

Design Choices

  • KY-009 RGB Full color LED SMD Module
    • \$I_{LED}=20\,\mathrm{mA}\$, ref1 ("KY-009 Specifications" table)

Datasheet Values

  • Light Emitting Diode, D1
    • \$V_{LED}(@I_{LED}=20\,\mathrm{mA}) = 2.0\,\mathrm{V}\$, ref2 (Fig. 1)
  • 2N3904 NPN transistor, Q1
    • \$V_{BE(sat)}(@I_{C(sat)}=20\,\mathrm{mA}) \approx 0.8\,\mathrm{V}\$, ref3 (Fig. 17)
    • \$V_{CE(sat)}(@I_{C(sat)}=20\,\mathrm{mA}) \approx 0.11\,\mathrm{V}\$, ref3 (Fig. 17)
  • Raspberry Pi GPIO pin
    • Minimum voltage for a logic HIGH output signal, \$V_{OH}=3.0\,\mathrm{V}\$, ref4 ("Voltage specifications")
    • Recommended maximum output current for a logic HIGH output signal, \$I_{OH(max)} = 16\,\mathrm{mA}\$, ref5


  1. Use Ohm's Law and Kirchhoff's Voltage Law (KVL) to calculate the resistance value for the LED's current limiting resistor Rx.

$$ \begin{align*} Rx &= \frac{V_{Rx}}{I_{Rx}}\;\;\;\;\leftarrow\text{Ohm's Law}\\ &= \frac{V_{CC} - V_{LED} - V_{CE(sat)}}{I_{LED}}\;\;\;\;\leftarrow\text{KVL}\\ &= \frac{5\,\mathrm{V} - 2.0\,\mathrm{V} - 0.11\,\mathrm{V}}{20\,\mathrm{mA}}\\ &= 144.5\,\mathrm{\Omega} \end{align*} $$

  1. Using a table of standard resistor values (example table), choose an available and appropriate resistance value for resistor Rx:

    • 143 Ω, 1 % tolerance
  2. Calculate the power dissipation in the chosen resistance value Rx.

$$ P_{Rx} = I^2\cdot Rx = (20\,\mathrm{mA})^2 (143\,\Omega) = 57\,\mathrm{mW} $$

  1. Select an available and appropriate power rating for resistor Rx. For beginners I suggest the following rule: if a component's operational power dissipation is \$x\,\mathrm{Watts}\$, then choose (purchase) a component that can dissipate \$\ge 2x\,\mathrm{Watts}\$.

    • \$2 \times P_{Rx} = 2 \times 57\,\mathrm{mW} = 114.4\,\mathrm{mW}\$
    • When purchasing Rx, select a part whose power rating is 1/8 W (125 mW) or greater.
  2. Transistor Q1 should operate in saturation mode, not forward-active mode. Select \$\beta _{sat} = 10\$, ref3, Fig. 17

  3. Calculate transistor Q1's base saturation current \$I_{B(sat)}\$ when the transistor is operating in saturation mode and \$I_{C(sat)} = 20\,\mathrm{mA}\$.

$$ I_{B(sat)} = \frac{I_{C(sat)}}{\beta _{sat}} = \frac{20\,\mathrm{mA}}{10} = 2\,\mathrm{mA} $$

  1. :: CHECK :: Ensure \$I_{B(sat)}\$ does not exceed the GPIO pin's maximum output current spec.

$$ 2\,\mathrm{mA} \le 16\,\mathrm{mA} = I_{OH(max)} $$

  1. Repeat steps 1 – 4 to choose available and appropriate values for resistor R1's resistance value and power rating.

    • Calculated value for R1

$$ \begin{align*} R1 &= \frac{V_{R1}}{I_{R1}}\\ &= \frac{V_{OH} - V_{BE(sat)}}{I_{B(sat)}}\\ &= \frac{3.0\,\mathrm{V} - 0.8\,\mathrm{V}}{2\,\mathrm{mA}}\\ &= 1100\,\mathrm{\Omega} \end{align*} $$

  • Chosen value for R1: 1.1 kΩ, 1 % tolerance

  • Calculated power dissipation in R1: 4.4 mW

  • Chosen power rating for R1 (>= 2x calculated power dissipation): 1/8 W


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.