1. We will be in Read Only mode (no new threads, replies, registration) for several hours as we migrate the forums to upgraded software.

2N2222 LED switch for PIC output

Discussion in 'Embedded Systems and Microcontrollers' started by tracecom, May 22, 2012.

  1. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    I want to place LEDs on the outputs of a PIC to indicate when each output is high, but I want the LED to load the output as little as necessary. So, I thought I would use a 2N2222 to control each LED as shown in the attached schematic. With the green LED that I plan to use, and a 1k resistor, the current through the LED is 2.38mA, and the LED is bright enough for my purposes.

    So, according to the "rule of thumb" (which I don't like, but don't have an alternative for), I would want .238mA of base current to Q1, which would calculate to 21k for R1. Sure enough, a 22k gives me .169mA, which I guess is close enough to the "rule of thumb." At that point, the current through the LED is 2.32mA, still bright enough for me.

    But, if I make R1 51k, the current through the LED is unchanged, but the base current is down to .073mA. What's wrong with that, and why shouldn't I minimize the base current so long as the LED current remains at 2.3x mA?

  2. Markd77

    Senior Member

    Sep 7, 2009
    At these low currents, it makes little or no difference, until you reach the gain of the transistor which should be a minimum of 75 for this transistor (at under 10mA from Phillips datasheet). The base current can be reduced to 1/75th of 2.32mA before there will be much difference, and that's for the lowest gain 2N2222s.
    tracecom likes this.
  3. MrChips


    Oct 2, 2009
    Your NPN transistor acts as a switch and is fully saturated.
    I don't bother with transistor current gain in such situations.
    I would put a resistor substitution box or variable resistor in place of R1 and adjust it until you get the performance you are seeking.
    tracecom likes this.
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    A base current of 1/10th of the expected collector current is one of those rules of thumb you often hear about, and you can often ignore it as you see.

    1/10 gives a margin of safety when very high currents are involved to keep the transistor well saturated. But with just a couple of miliamps in the collector there isn't a significant power loss anywhere.
    tracecom likes this.
  5. BillO

    Distinguished Member

    Nov 24, 2008
    You have a lot of good answers already. I'd just like to add the that the 2N2222 is not the ideal transistor for such low currents. If you wanted to minimize your load on the MCU as much as possible consider a transistor like the 2N5232A which will provide a minimum gain of about 250 at 2.5ma and allow you to get away with a 430K base resistor. Or better still, use a little mosfet and have basically no load at all on your MCU I/O pin.
    tracecom likes this.