LEDs + 2N2222A w/PICAXE

Thread Starter

Garoad

Joined Apr 24, 2012
26
I'd like to use a PICAXE to switch a few 2N2222's powering a string of 4 series LEDs on and off. I figure I'll need to add transistors used as switches so I can use the source's full 12v to drive the LEDs (PICAXE runs on a regulated 5v so I can't use it's output to drive more than 1-2 LEDs).

Here's the basic idea (the other 3 PICAXE outputs would also be wired to the same components as output0):



The issue I'm having is, this works fine with the 2N2222 when it's connected to one LED, but once I add a few more they won't light. I'm basically guessing at what the transistor's base resistor value should be--it doesn't seem to matter what resistance is used. (I've through most of the book Make: Electronics, but I didn't grasp transistor fundamentals well enough from it.)

The LEDs I'm using light fine from my 12v source when wired with a simple 100 ohm resistor. (I believe the Vfs are 2v red, 2.5v green, 3v blue, 2v yellow or so. Maybe they need to all have the same Vf per string?) Any ideas what I'm doing wrong here? How do I calculate the resistor needed for the transistor's base?

r = (e / i), so r = (5v / .002A) to get .020A out of emitter, therefore r = 2500ohm?
I think I'm screwing something up there, maybe because I'm ignoring the 100ohm resistor connected w/LEDs in series.

Since this is basically an office mini-tree Christmas project I want to minimize wiring as much as possible, that's the main driver behind using LEDs in series rather than parallel (well, I want to avoid the extra resistors too). Also I realize I could do something very similar with 555 timers (and I still may) but I figure a programmable PICAXE will be a cooler conversation starter around the office.
 

Thread Starter

Garoad

Joined Apr 24, 2012
26
Confused here - it is connected to ground via the 100ohm & LEDs, are you saying I need an additional connection? (And wouldn't this require an additional resistor to avoid burning out the transistor?) I'm afraid I'm pretty confused about why that'd be needed.
 

takao21203

Joined Apr 28, 2012
3,702
no the LED chain needs to be connected to Vcc, and the transistor inserted at the bottom of the chain.

You only need to re-arrange the components.

I often use digital MOSFET since they don't need base resistor and don't drop voltage.

If you want to keep the circuit like it is, you need a PNP transistor.

So the emitter goes to ground, and the collector is connected to 100 Ohms resistor, then the LEDs. It's no difference if you put the LEDs first or the resistor.
 

#12

Joined Nov 30, 2010
18,224
Let me clear this up. The way you have this, the PICAXE can only give the transistor zero to 5 volts, and the emitter is always a lower voltage than the base. You can only get about 4.5 volts out of that transistor the way you have it wired up. You need to move the transistor to the bottom of the string so the LEDs get the full 12 volts and the transistor only grounds the string. The base resistor should be 2200 ohms. You should change that 100 ohm resistor to 120 ohms, up to as much as 470 ohms if you don't have a 120. The LEDs will just be a bit dim until you can get the right resistor (120 ohms) installed.

Changing to a PNP transistor won't work because it will always be "on" because the PICAXE can only give the transistor 0 to 5 volts and that will activate the transistor at all times.
 
Last edited:

Thread Starter

Garoad

Joined Apr 24, 2012
26
Uh, that works perfectly!



Now I'm just trying to understand why. That explanation helps, but I'm not understanding why the emitter doesn't put out 12v in the original case, since the collector was getting 12 "put into it".

I guess I need to go through a good transistor switching tutorial, or something. What determines how much voltage the emitter puts out?
 
Last edited:

Thread Starter

Garoad

Joined Apr 24, 2012
26
The base resistor should be 2200 ohms. You should change that 100 ohm resistor to 120 ohms, up to as much as 470 ohms if you don't have a 120. The LEDs will just be a bit dim until you can get the right resistor (120 ohms) installed.
With a base resistor of 2200ohms - are you saying the bumbling calculation I made above where I got 2500ohms was about right, or was that just dumb luck?
( r = (e / i), so r = (5v / .002A) to get .020A out of emitter, therefore r = 2500ohm? )

I'm surprised 20 ohms (100 to 120) really matters so much. I'm also not getting why the LEDs would be dimmer with the lower 100ohm resistor than with a 120. I would have thought it'd make them brighter.

 
Last edited:

takao21203

Joined Apr 28, 2012
3,702
These 20 Ohms would not matter much since also the transistor won't have 0 Ohms resistance.

2.2K or 3.3k does not really matter but if you increase it, at some point LED brightness will go down.

As for NPN, the conduction begins if the base has a potential at least 0.7 volts higher than the emitter.

I suggest to build a transistor tester:

Connect a 50k pot to both + and -, apply some batteries etc., and inline a LED + 470 Ohms before the collector. And connect the base with 470 Ohms as well, from the pot wiper. (pot = potentiometer).

If the transistor is OK, you will see turn-on point.
If you want, also add a 250k or 500k pot inside the base/50k pot connection, and you will see brightness variation (= different current).

PNP can be odd to use for some people since they work with negative voltages.
 

Pencil

Joined Dec 8, 2009
272
With a base resistor of 2200ohms - are you saying the bumbling calculation I made above where I got 2500ohms was about right, or was that just dumb luck?
( r = (e / i), so r = (5v / .002A) to get .020A out of emitter, therefore r = 2500ohm? )
You are correct to assume 20mA collector current needs a
base current of 2mA when using a transistor as a switch.

The difference in your calculation and that of the esteemed #12
is that I assume he took into account the Vbe of the transistor.

Example:
Collector current: 20mA
Base current: 2mA
Vbe of 2n2222: ≈.6V
Output voltage of PICAXE: ≈5V (check datasheet)

(5V-.6V)/.002A=2200Ω


I'm surprised 20 ohms (100 to 120) really matters so much. I'm also not getting why the LEDs would be dimmer with the lower 100ohm resistor than with a 120. I would have thought it'd make them brighter.
I think you are misunderstanding him. He meant using a 120Ω-470Ω
resistor would make them dimmer. The 120Ω would probably not
make a noticeable difference, but the 470Ω would appear dimmer.
 
Last edited:

takao21203

Joined Apr 28, 2012
3,702
Ahh... I was was thinking the relation that matters was collector to base, and I wasn't aware 0.7 was a magic number here.
I am not really a bright university genius, but usually after a while I get along with components if need be. Some years ago I did not understand myself transistors properly, but browsing datasheets (for instance from http://alldatasheet.com) really helped. Even if I don't understand the use of all the graphs shown, I take a look at least.

And what I also do I browse, or in the past have browsed, websites from commercial vendors, such as Farnell and Radionics. If I search for a power transistor let say, I would examine various types that could match, and would order a few pieces each for testing, or to have them available. Later when I know a component, I would order 50pcs or 100pcs etc.
 

#12

Joined Nov 30, 2010
18,224
I went for 120 ohms because .02 amps is the ABSOLUTE MAXIMUM current allowed for common LEDs.
The sum of your LED voltages is 9.5V. A properly saturated transistor can have as little as .2 volts from collector to emitter.
12-9.5-.2 = 2.3 volts
2.3/.02 = 115 ohms MINIMUM.

This points out the idea that the emitter to base voltage is more than the emitter to collector voltage in a saturated switch. You pick up these tiny, nit-picking points as you become more experienced.
 
Last edited:
Top