2
\$\begingroup\$

I'm trying to get my head around how to properly use NPN transistors to limit the needed current from my Raspberry PI GPIO.

I want to drive a Luxeon Rebel LED from Phillips (https://www.sparkfun.com/products/9637), and I have drawn up this kind of circuit for it:

GPIO connected NPN and high power LED

I'm not that experienced with transistors, so I might be doing something very foolish here. But my thinking was that if I have a 9V battery, and I would like to use GPIO pin on my raspi, something like this might work.

I calculated the resistor value for the LED1 with the information from the sparkfun website information (typical forward voltage of ~3V) -> R = (9V - 3V) / 0.2A. So I got 30 Ohms from there.

The battery and raspi ground would be connected. Is there something I am doing in a stupid or even dangerous way ? I want to understand how properly use NPN transistor for this kind of purpose..

\$\endgroup\$
4
\$\begingroup\$

With those value resistors, you need a transistor with at least 25 hfe, and more than 275mA collector current. ~6v / 22Ω = 0.272A (272mA) of current through the LED, and (3.3v - 0.6v) / 330Ω = 0.0081A (8.1mA) of current through the base.

A common 2n2222 transistor would work. Otherwise, you got it right. Also, you might want to go with the actual 30Ω or higher value resistor, to prevent overdriving the led.

\$\endgroup\$
  • \$\begingroup\$ thanks for your quick reply! Can I ask a bit more clarification about that 25hfe? I read about it, and it seems to be related to gain. What should I consider when choosing a transistor in the light of hfe? You are right, if I put 30 Ohm resistor, I would get exactly 200mA, silly me I forgot to change the text in the picture after I re-calculated the resistor value. Also may I ask if If I increase the GPIO side resistor R2 to 1K to decrease load on the GPIO to somewhere around 2.7mA, would that have affect on the circuit ? \$\endgroup\$ – julumme Oct 15 '13 at 16:24
  • \$\begingroup\$ The HFE is the gain. It takes the base current and multiply it by the gain to tell you how much current will be allowed through the collector-emmiter. The 2n2222 has a hfe of at least 50 with the collector current of 150mA and collector-emitter voltage of 1v. So 2.7mA * 50 would only let 137mA through. You need atleast 5mA. But for the most part, there is no real difference to the RPI in providing 8mA or 2.7mA. \$\endgroup\$ – Passerby Oct 15 '13 at 16:31
  • \$\begingroup\$ @Passerby may I know what is the 0.6v in your "(3.3v - 0.6v) / 330Ω = 0.0081A" please? Is it the min value of Base−Emitter Saturation Voltage of the 2n2222? \$\endgroup\$ – Huy.PhamNhu Jul 20 '17 at 18:30
  • 1
    \$\begingroup\$ @HUY the forward voltage drop of transistors base diode junction. It varies but 0.6 to 0.7v is typical for the 2n2222 at most currents. \$\endgroup\$ – Passerby Jul 20 '17 at 19:12
4
\$\begingroup\$

The main problem of this schematic is still not mentioned in the answers. It is the very big power on the current limiting resistor. \$ P = \frac{U^2}{R} = \frac{6*6}{30} = 1.2W\$

This will have two effects:

  1. The resistor must be rated for this power and still will be very hot.

  2. The efficiency of the schematic will be pretty low - 0.6W on the LED vs 1.2W on the resistor = 30%; As a result the battery will be discharged much more faster than possible.

For such powerful LEDs I would suggest another solution, described in my answer on another similar quesstion. The schematic from this answer is directly applicable for 9V supply, but a Schottky diode have to be connected in series with the LED, because it will not withstand 9V reverse voltage.

\$\endgroup\$
2
\$\begingroup\$

This is a proper usage of an NPN transistor, with some caveats.

An NPN transistor requires constant current input to the base pin to keep the current flowing between the collector and emitter. The amount of current that can flow between C & E is the gain multiplied by the base current. The amount of power a transistor is dissipating is the voltage drop across C&E multiplied by the current flow. For a small transistor, this is about 0.3v, 1.0v for a large transistor, and up to 4 volts (!) for a darlington. This voltage drop needs to be calculated in just like the LED's voltage drop, and the power is expressed as heat in the switch itself -- causing it to heat up (and may require heatsinking).

A 320 ohm resistor on a 3.3v GPIO line will flow ~10 milliamps, and to move 200 milliamps on the C&E lines will require a minimum gain (hFE) of 20, which is the minimum supplied by a power transistor such as the TIP41C. A small signal transistor like a 2N2222 has a gain in the hundreds, but a max current of 200 milliamps. It's a chicken-and-egg scenario and will likely require a more expensive darlington pair transistor like the TIP120. The Pi will be constantly supplying power while the LED is on.

\$\endgroup\$
  • \$\begingroup\$ You forgot to calculate for the VBE drop (typically 0.6 to 0.7v) There will only be 8mA at the base. Also, the 2n2222 has a max current of 1 Amp, not 200mA. You are thinking some versions of the 2n3904. A TIP120 is overkill. \$\endgroup\$ – Passerby Oct 15 '13 at 16:25
  • \$\begingroup\$ In that case your answer is more correct than mine, have an upvote. \$\endgroup\$ – Bryan Boettcher Oct 15 '13 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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