Hard to condense this question into a succinct subject, so forgive me if that's not at all clear.
I first noticed this with schematics showing using an Arduino to control a relay, where +5V goes into the relay's coil, then connects to a NPN transistor (with the Arduino driving the transistor's base) before finally terminating at ground. In fact, it seems that every schematic showing a transistor-switched load and using a NPN transistor does this -- Vin goes directly to the load, then to the transistor, and finally to ground. Trying to find if there's a reason for this, I found this page, which says NPN transistors should switch Gnd and PNP transistors should switch Vin -- but it doesn't go into why.
In my tinkerings I've always used switches to control the voltage coming into the circuit, not the voltage flowing out to ground. I realize either way works, as any open circuit won't flow current, so this is just my own convention. As I enter the world of fancy things like transistors, this is how I've always envisioned using them -- basically direct substitutes for switches. (Yes I realize they have other uses, but I don't think that's relevant to this question -- unless it is.)
Is there a reason for using NPN transistors to switch Gnd instead of Vin, but PNP to switch Vin instead of Gnd? Or is this simply a convention, and if so is it a wide enough convention that I should follow it in my designs as well? And if there's some reason for this, does it apply to mechanical switches (including relays) as well?
Because it is easier to supply a steady current current into the NPN base when it has a hard reference to ground. If the base is at VCC, the voltage may have to rise above that for current to flow into the base. Also, once it turns on, the base current may vary wildly if the effective emitter resistance changes.
If you try low side switching on an NPN (load in the Emitter-Gnd) you'll fine that you can't have your load at a voltage above the Base voltage.
A lot of the time you want to use a 5V or 3.3V Arduino output to control switching of a load at a higher voltage, say 12V. The only way to do this is to have the load between +Vcc and Collector so that the full supply appears across it when you saturate the Base-Emitter junction.
Ah, of course, because transistors work by comparing the base to the emitter. (Yes, I know this isn't entirely accurate, but it's good enough for my own comprehension.) And of course since other types of switches (again, yes, I know a transistor isn't a switch per se) don't function in anything even remotely like this manner, it's not something I have to worry about for them.
Since NPN relies on a positive differential, it should have a straight connection to Gnd to get a more reliable baseline; similarly, since PNP relies on a negative differential, it should have a straight connection to Vin.
Thanks, this is one of those simple concepts I never would have understood without help. Now if you'll excuse me, I've got a few circuits that need to be redesigned somewhat...
tack:
If you try low side switching on an NPN (load in the Emitter-Gnd) you'll fine that you can't have your load at a voltage above the Base voltage.
A lot of the time you want to use a 5V or 3.3V Arduino output to control switching of a load at a higher voltage, say 12V. The only way to do this is to have the load between +Vcc and Collector so that the full supply appears across it when you saturate the Base-Emitter junction.
This I don't understand. How can the position of the transistor (either between Vcc and load, or between load and Gnd) affect the voltage across the load? This bit seems critically important since I exactly am, in a couple of my designs at least, switching (relatively) high-voltage loads.
With NPN on low side (switching to Gnd) the '328P can output sufficient current to turn the transistor fully on.
With PNP, the base needs to be at the high voltage level to turn the PNP off, and the base pulled low to turn the PNP on. '328P can pull low no problem, but cannot drive high past 5V - and if you try and tri-state the output to let a pullup resistor bring it up to 12V, that blows the '328P pin.
So an NPN is used to pull the PNP base low instead, while the '328P just drives the NPN at normal 0/5V levels.
Kromey:
Ah, of course, because transistors work by comparing the base to the emitter. (Yes, I know this isn't entirely accurate, but it's good enough for my own comprehension.)
Correct. If the emitter isn't at a known voltage level then it's difficult to apply the right voltage to base (maybe impossible if you only have 0-5V to play with).
Transistor circuits get tricky when the voltage level at the emitter is dynamic. The interplay between emitter+base can create a feedback loop.
You see this sort of thing in (eg.) constant current circuitry where the transistor is arranged so the voltage level at the emitter is proportional to the current. This creates a resistance which is inversely related to the current flowing through it.