[ electronics ] Message 1688 (0 left): Mon Aug 23, 2004 6:26pm From: dolphin (dolphin@eeph.com) Subject: heres some info I have prepared for just such a question The modern part number for the 2N2222 is PN2222 If you are running on batteries, then you want to conserve power and not waste it in lossy devices like regulators or resistors, you want to "burn" as much as you can in your LEDs. LEDs like any diode eat an amount of voltage out of the power they are fed. If we take the common red LED, the loss is 1.7V nominal per diode. If we built a simple circuit: +V----[RESISTOR]----->|----->|----->|------GND/V- A K A K A K LED1 LED2 LED3 ^ ^ ^ | | | 5.1V 3.4V 1.7V The voltage across the LEDs remains constant more or less no matter what the voltage used. However the LEDs will glow brighter as the supply voltage goes up. Once the power supply drops below 5.1V, this circuit will be totally dark. That is to say the LEDs stay open until they have enough forward voltage. If this circuit ran from a CONSTANT (regulated) 6V supply and you wanted to run the LEDs at 20mA each, then you could calculate the resistor required: The resistor must pass 0.02A at (6V - 5.1V) or 0.9V. ohms = volts / amps so 0.9 / 0.02 = 45 OHMS the resistor will dissipate some heat so calculate how much: watts = ohms * (amps^2) so 45*0.02^2 = 0.018 watts note that that is a very small amount of lost power However this circuit is VERY voltage sensitive. if we increase the voltage to 7V = the LED current will jump to 43mA - and many LEDS will die if operated at 100% duty cycle at that current level. On the other hand a single LED and resistor in the 6V circuit would draw the same 20mA and only light ONE LED - the rest of the energy being wasted. resistor drops 4.3V in that case. making ohms = 215 and watts lost as heat = 0.086W Driving 300 LEDs with the first circuit takes 2A Driving 300 LEDs with the second circuit takes 6A Obviously we want to find a compromise. * Ideal circuit: uses a switching regulator to set the voltage to the ideal level for a small resistor much like circuit 1. * Less ideal, if you don't mind brightness variance as the battery droops (for example) - set a minimum and maximum system voltage. Find the "knee" of the battery discharge curve and set the minimum voltage to that. Find the maximum voltage of the system with a fresh battery. Determine the acceptable brightness variation over the battery life. Lets say we have a car battery. and the full charge is 13.8 - dead is 10.2V. We can live with a 3:1 variation in brightness. That 3:1 is the range of voltage drop across the resistor. So that means our LED voltage will be 13.8 - (13.8-10.2*3/2) or 8.4V. That could be 5 RED LEDs or 2 WHITE LEDS. We could get away with 3 WHITE LEDs (9.3V total but the 1/3 brightness voltage would go up 10.8V. Still pretty useful. -------------------------------- Driving a transistor with a PIC. PN2222A http://info.hobbyengineering.com/specs/Fairchild-PN2222A.pdf Lets take the PN2222 transistor. If driven with what a PIC output can supply (lets say 15mA to be conservative) then we look at the data sheet and see that this part has hFE of 35 minimum under all conditions. That means that we must supply 1mA of "drive current" for each 35mA of "load current" to have the transistor be "fully on". If we supply too little drive for the load the transistor stays in a resistive mode and dissipates some of the current as heat. If there is no "safe area" or "current limit" circuit then the transistor gets too hot, and shots off even more and gets even hotter and so on until meltdown. It's called "thermal runaway" and is very bad. So remember to check the data sheet for the "beta" or "hFE" ratings before designing. In this case we can drive a load of 525mA (lets say 400mA if we want a super-reliable circuit) with one PIC output and a cheap PN2222 resistor AS LONG AS IT IS OPERATED AS A SWITCH (i.e. fully on or fully off only). If we operate it in the "limear range" then we have to worry about power dissipation, just like any other resistive device. The data sheet says that we can drive as much as 1000mA before damaging the collector, (max. continous collector current or Ic) so we're very safe there. The voltage spec shows 60V max across the transistor in the OFF state (collector to emitter breakdown voltage) and that's good too. *Decoupling and so on not shown for the PIC (12V) (5V) +-[- Car Battery +]-[FUSE]-+-[5V regulator]--[V+ PIC* Out V-]---RTN | | | | RTN | RTN | +--[10u Tant]--+ > Rb = 220, 1/4W | +-VVVVV-->|-->|-->|--+ > (~3.5V total RTN | | > drop at 15mA) +-VVVVV-->|-->|-->|--+ | | | | +-VVVVV-->|-->|-->|--+ __b__ | / \ +------c-/ V-e-----RTN three strings of three leds shown. calculate R as described above. keep total current to 400mA @ max battery voltage. that would be 20 strings at 20mA each. using a darlington transistor causes an additional volt to be lost in the circuit and so reduce the LED R values accordingly. FETs rated for "logic level turn on" can be used in the circuit as well. E=drain C=source B=gate in that case. IRLZ34 can drive so many LEDS it's not even funny (7A current rating?) and can easily be driven by the PIC. If there is a LOT of wiring in the LED circuit consider a 5.1V claming zener from gate(K) to anode(A)