3
\$\begingroup\$

I am working on a circuit that controls a solenoid through the use of an Arduino. One question I had was if there was any advantage to using a PNP transistor over an NPN transistor? From class, I know that PNP's are usually better for pulling devices high and NPNs are better for pulling devices low, although I am unsure why this is the case.

For reference, I want to use an Arduino to control the transistor that activates the solenoid. So when the Arduino outputs a HIGH signal, the solenoid should activate, and at LOW signal, it shouldn't do anything. After searching around online, it seems that a general schematic for that would look like this (asides from the BJT):

enter image description here

It seems like an NPN would be the best choice for this scenario, but I don't really understand how connecting the solenoid to ground would activate it? It seems to logically make more sense to have the solenoid connected to ground all the time, then when it's time to activate the solenoid, simply pull up the solenoid using a PNP. However due to the inverse behavior of a PNP to an NPN, it would take a little more work then just having the Arduino output a HIGH signal.

\$\endgroup\$
  • 4
    \$\begingroup\$ Ah, let me see. The EE guys usually prefer NPN over PNP for many reasons, including the following: (1) It is usually more efficient to use NPN, (a) resulting cheaper because of mass production, (b) resulting more tutorials, references, and build up a upward spiral, while PNP goes down a downward spiral. (2) it is usually more efficient to do pull up an input, and activate something by pulling down, (so called Low level active/enable). / continue, ... \$\endgroup\$ – tlfong01 Oct 29 at 1:09
  • 1
    \$\begingroup\$ / continued, ... You might like to skim my answer in the following Q&A to find more answers to your question: (1) How to properly use a relay module with JD-VCC from Arduino/Raspberry? Asked 4 months ago, Viewed 1k times electronics.stackexchange.com/questions/505318/…. Happy learning. Cheers. \$\endgroup\$ – tlfong01 Oct 29 at 1:11
  • 6
    \$\begingroup\$ I don't really understand how connecting the solenoid to ground would activate it ... why would you fail to understand that connecting the bottom of the solenoid to ground completes the circuit and activates the solenoid?... the solenoid bevomes connected across the power supply pins \$\endgroup\$ – jsotola Oct 29 at 2:14
  • 1
    \$\begingroup\$ Ah stupid me didn't even register the solenoid wasn't grounded by default, thanks! Also @tlfong01, thank you for all the facts and the link. I have indeed found more documentation and cases where someone uses an NPN over a PNP. \$\endgroup\$ – transienttoast Oct 29 at 2:37
  • 2
    \$\begingroup\$ @tlfong01 Please stop answering in the comment section. The warnings and policy is there for a reason. You could have written a long answer instead of all the comments you have spread out over this question and answer. \$\endgroup\$ – pipe Oct 29 at 18:44
8
\$\begingroup\$

any advantage to using a PNP transistor over an NPN transistor?

It's largely a matter of economics and efficiency. In general, for a fixed price point, NPN and N-channel devices can carry more current, and for a fixed current capacity, NPN and N-channel devices are cheaper. For example, take the 2N440x, TO-92, 600mA, 40V. The 4401 is NPN, $0.293; the 4403 is PNP, $0.299. Other devices can have more dramatic differences - wider price gaps, or even availability only in NPN and not PNP.

That aside, take a read through this for example. NPN devices have faster charge carrier (electron) mobility; more convenient reference voltage (ground) when in the most common configuration, common emitter; and less die area.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ I see the economic benefits, however since I am not planning to use a lot those don't really apply to me that much. Sorry if this is kinda obvious, but since NPN devices has faster charger carrier mobility, does this mean that when activating the transistor, the solenoid will activate faster due to faster current? Also I'm not quite sure what is meant by less die area and convenient reference voltage? If I were using a PNP would I not be connecting drain to solenoid and source to a 12V source? \$\endgroup\$ – transienttoast Oct 29 at 2:44
  • 3
    \$\begingroup\$ For a solenoid, speed difference will really not matter to you; that calls for slow, powerful switching. \$\endgroup\$ – Reinderien Oct 29 at 2:52
  • 1
    \$\begingroup\$ Die area means that, on a physical silicon wafer during the manufacturing process, PNP devices are proportionally bigger. It won't always affect the size of the IC package, but will affect the cost since fewer PNP devices can be manufactured on one die. \$\endgroup\$ – Reinderien Oct 29 at 2:54
  • 2
    \$\begingroup\$ In a typical circuit there may be many positive rails, but usually only one important negative rail - ground. In a common-emitter (or common-source, in FET land) configuration, N-type devices connect their emitter to ground, which is often more readily available in PCB layouts, or shared between more subcircuits than disparate voltages like 3.3V, 5V, 12V, 24V etc. \$\endgroup\$ – Reinderien Oct 29 at 2:56
  • \$\begingroup\$ @transienttoast, (2) Ah, the relay is actually a ridiculously slow guy and can switch at most 10Hz, ie, 10 times a second. On the other hand BJT NPN or PNP can easily switch 1 million times faster, ie the order of 10MHz. (2) I am not sure of your application, but you might consider a N-Channel power MOSFET, eg IRL540N, instead of a slow relay which requires about 70 mA to switch. A power MOSFET can handle bigger switching current than a relay, and also many many times faster, and often cheaper, more durable, less space, quieter (no clicking sound). But me ok zoomer, still loves the relay! :) \$\endgroup\$ – tlfong01 Oct 29 at 3:26
9
\$\begingroup\$

It’s mostly about convenience.

Low-side drive like the NPN shown can be controlled directly by ordinary logic levels yet can manage a higher controlled voltage (like the +12V shown in the example.)

A PNP (or P-FET) can be used to switch on the high side, if the switch supply is the same or lower than the logic level.

Example:

schematic

simulate this circuit – Schematic created using CircuitLab

Otherwise, read on.

For higher-than-logic voltages like the example, a high-side drive PNP needs a level shifter (such as another NPN) to translate the voltage up. The shifter ensures that the PNP base is pulled up high enough to reliably turn off the device.

Example:

schematic

simulate this circuit

(Some notes. R3 isn't strictly necessary, it pulls the Q1 base up to +12 when Q2 is off to improve noise immunity. R2 should be sized based on the required Q1 saturation current.)

Same goes for MOSFETs: a low-side N-FET can be switched with logic; a high-side P-FET needs a level shifter if it's switching a voltage higher than the logic level.

And here's the high-side switch, with MOSFETs:

schematic

simulate this circuit

NPNs (and their N-FET cousins) offer somewhat better current handling capability than the P-type devices, but only slightly so given modern process technology.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ A level shifter is only needed if there is a non-Vdd voltage at the drain. That's the case here (12V) but it won't always be. \$\endgroup\$ – Reinderien Oct 29 at 1:42
  • 1
    \$\begingroup\$ Does this mean whenever I am using a microcontroller such as Arduino, I should aim to always use an NPN transistor in switching applications because of simplicity (IE direct control from logic outputs versus level shifter)? \$\endgroup\$ – transienttoast Oct 29 at 2:46
  • 3
    \$\begingroup\$ @transienttoast if you are switching electric device use NPN, but if you are switching electronic device (eg. switch power of LCD/OLED display) better use high side switching (PNP). In NPN configuration and switched off state current will flow from power supply to GND through data/control pins of electronic device - quite expensive lesson learned. \$\endgroup\$ – ufok Oct 29 at 10:58
  • 1
    \$\begingroup\$ @tlfong01, Where do you get this unbridled imagination from? And that subtle sense of humor? Maybe you are inspired by the Einstein's thought about imagination:)? \$\endgroup\$ – Circuit fantasist Oct 29 at 19:10
6
\$\begingroup\$

A logic 'high' or 'low' is relative to the polarity of the reference.

Should the reference be negative, 'high' would be positive and 'low' negative.

Likewise, should the reference be positive, 'low' would be positive and 'high' negative.

In the present context, an NPN transistor would be used, should the ground be negative.

enter image description here

Accordingly, a PNP transistor would be used, should the ground be positive.

enter image description here

The configuration is the same in either case.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ However, connecting the second one to an Arduino is ... not so simple. \$\endgroup\$ – Brian Drummond Oct 29 at 12:21
  • 1
    \$\begingroup\$ Of course, Brian. But why would one need to do that? \$\endgroup\$ – vu2nan Oct 29 at 16:11
  • 1
    \$\begingroup\$ It is simple, if you ignore the ground symbol which serves no purpose except to make the schematic confusing, and the Arduino has open-drain outputs. In that case, the uC can pull the base resistor down to the "-" terminal, or let it float. \$\endgroup\$ – Phil Frost Oct 29 at 18:29
  • 1
    \$\begingroup\$ Yes, it's fun to think about what 'ground' means, but the reality is that the PNP as shown would be the equivalent of high-side switching if actually connected to a real microcontroller system - you know, one that has a negative ground. \$\endgroup\$ – hacktastical Oct 29 at 20:14
  • 1
    \$\begingroup\$ @hacktastical High-side switching is not an unusual thing, and if you look at the schematic upside-down it's exactly ordinary high-side switching. I was mistaken about the Arduino having open-drain outputs, but I'm sure you can think of some ICs that do have open-drain outputs. You could have pointed that out without calling my observation pointless, which would be a little less insulting. \$\endgroup\$ – Phil Frost Oct 30 at 2:06
4
\$\begingroup\$

It seems to logically make more sense to have the solenoid connected to ground all the time, then when it's time to activate the solenoid, simply pull up the solenoid using a PNP.

Why is that? Keep in mind the solenoid doesn't "know" which end is ground. "Ground" is a concept people made up to simplify discussion about a circuit. Electronic components know nothing about it.

Your circuit could be redrawn like this:

schematic

simulate this circuit – Schematic created using CircuitLab

Now the solenoid is connected to ground all the time, but this circuit is identical to the one in your question. The choice of what to call "ground" is arbitrary, and while this particular choice is non-conventional and confusing to talk about because it violates the conventions of what "ground" is typically, it's electrically identical.

This is because "voltage" is measuring electric potential difference, and because it's difference means it doesn't matter which point we decide to call "0V" or "ground". All the solenoid cares about is that there's a 12V difference between its terminals.

Now of course you could build the circuit with a PNP, like so:

schematic

simulate this circuit

Some ICs (usually digital logic) have open-drain outputs like this, or you can replace M1 with a discrete MOSFET or an NPN transistor. Some microcontrollers might have them, but the AVR on an Arduino does not.

The only change really is you might want to increase the value of R1, since the base current would otherwise be higher due to the additional voltage. But given the above explanation about the arbitrary nature of ground, is there any particular advantage to this solution?

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Phil Frost, An exciting story about ground and its variations... BTW nice to see you again. Where did you go? SE EE needs people like you, me too:) Honestly, one of the reasons I came here was you... \$\endgroup\$ – Circuit fantasist Oct 29 at 18:56
  • 1
    \$\begingroup\$ @Circuitfantasist I've been active on ham.se lately. Only time for one :) \$\endgroup\$ – Phil Frost Oct 29 at 19:08
  • 1
    \$\begingroup\$ Oh, you radio amateurs are crazy people:) \$\endgroup\$ – Circuit fantasist Oct 29 at 19:14
  • \$\begingroup\$ Nope nope nope. You can't use a microcontroller OD output that way. They're not truly 'open drain' and unless otherwise specified, any I/O voltage must be between Vdd and Vss. The example you show would destroy the part, or at least have a leakage path between the Q1 base and the I/O pad. \$\endgroup\$ – hacktastical Oct 30 at 1:39
  • \$\begingroup\$ @hacktastical I'm not sure there are no microcontrollers that have them, but you're right the AVR that might be in an arduino doesn't, so point taken. \$\endgroup\$ – Phil Frost Oct 30 at 1:56
0
\$\begingroup\$

Although it has been said several times, I will try to say it even more simply and clearly.

The simple truth is that, in most cases, the input sources and next loads are connected with one (negative) of their two terminals to the negative terminal of the power supply assigned as a zero reference point ("ground"). The transistor should be also connected to this point with its "negative terminal"; so it should be NPN type.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ But in that low-side switch circuit in the question, the load is not connected to the ground reference point. And your answer doesn't tell why this would be the "simple truth". \$\endgroup\$ – ilkkachu Oct 29 at 20:50
  • 1
    \$\begingroup\$ @‭ilkkachu, Thanks for the response. I mean the usual case for cascaded stages where the load is connected in parallel to the transistor. Really, here the load is connected in series to the transistor but that does not change things about the transistor (it is in the same place). \$\endgroup\$ – Circuit fantasist Oct 29 at 22:05
  • 1
    \$\begingroup\$ @tlfong01, My answer was more general - about a multistage amplifier, where the output collector-emitter part of the current transistor drives the input base-emitter junction of the next transistor acting as a grounded load. Actually, I have explained why NPN but not PNP transistors are widely used to build transistor amplifiers... \$\endgroup\$ – Circuit fantasist Oct 30 at 7:02
  • 1
    \$\begingroup\$ @tlfong01, You are an interesting person with this "philosophical" reasoning... I see some resemblance between us:) I just cannot agree with the term "common collector". Maybe "sourcing", "sinking" and "sourcing & sinking is a more appropriate determinant before "open collector"? \$\endgroup\$ – Circuit fantasist Oct 30 at 8:27
  • 1
    \$\begingroup\$ About my "philosophical" reasoning", I have a BA degree in Philosophy and History, so I do have particular interest in using human language to explain hard to explain things (OK, like Einstein) and looking things in the past (PNP/NPN BJT) and predict things in the future (All MOSFETs in 2035). Predicting things in the near future is very important for IT pros in strategy planning and innovative/start up businesses. Ah, I also have an MA in Education, so I am interested to teach (or learn together) in a newbie friendly way, say, understanding by using metaphors. Perhaps more later. \$\endgroup\$ – tlfong01 Oct 30 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.