I want to use a 2N2222 as a low side switch to turn on a 12V bulb. It's one of those flickery flame effect bulbs, so it doesn't have a constant current, but I think it maxes at around 160mA. And actually, I'd like to turn on 2 of these bulbs, so ~320mA.
I've used these in the past with 5V going to my transistor base, but is there any reason that my base voltage couldn't also be 12V? Is the only requirement that the base voltage be higher than the collector?
Well you could use basically almost any voltage as long as you operate the transistor in saturation. Just play a little with the resistor on the base. Set a current value on the base and then you can choose a resistor. Basically it goes like this: (Vin-Vbe)/Ibase.
VBase has to be ~ 0.7V greater than Vcollectoremitter.
If the NPN is sinking current to Gnd, then Vbase just needs to be > 0.7V.
Next consideration current into the base.
20-30mA from an Arduino is usually plenty.
So you need a resistor to limit the base current as Vsource (5V or 12V) is well above 0.7V.
You know the current you are trying to put into the base, say 30mA, 0.03A.
Then you have a series circuit of Vsource, Vresistor, and Vbase-emitter, and the desired current 0.03A. Vr will just be Vsource -Vbase-emitter.
Using Ohm Law, V=IR, or V/I = R, we can find a suitable resistor:
So (Vs - Vb)/0.03A = R (with the collectoremitter grounded, this will be Vbe).
With 5V: (5V - 0.7V)/.03A = 143 ohm
With 12V: (12V - 0.7V)/.03A = 377 ohm
You can use 150 ohm and 390 ohm, and calculate the slightly lower current into the base.
I am assuming you are using a resistor in series with that 5V connection.
If there is no Arduino involved then yes you can connect the base to 12V if you use a suitable resistor to restrict the current to the saturation current that you will find in the data sheet for the transistor you are using.
You would assume wrongly, but I have since learned. My Arduino for the previous project kept restarting after I hooked up my resistor-less transistor (because of course it would), but I discovered that it worked when I had power from both USB and the power jack. So I just left it like that. I know, shameful.
Anyway, thanks for the answers, everyone. The Vbase is actually coming from the output of a 555 timer, which is a new area for me. I'll likely have some questions about that too, but I'll save that for an appropriately-titled topic.