# Switching Relay with NPN and PNP transistors

I'm designing a locker system using Arduino.
Due to system requirement, two IOs will be used control the relay, and only when two IOs are ON, then the relay will be triggered.

• PNP = BC807
• NPN = BC817
• Coil = 720 ohm, 20 mA
• Diode = 1N4148

My question is will PNP be switched on/off reliably?
Any risk to consider here?

Any suggestions are welcome.

## migrated from meta.stackexchange.comNov 22 '18 at 8:03

This question came from our discussion, support, and feature requests site for meta-discussion of the Stack Exchange family of Q&A websites.

• What you mean by ON state of the IO? Logic low or logic high? – soosai steven Nov 22 '18 at 8:51
• Logic High (5V) on Arduino output pin – Kean Nov 22 '18 at 11:14

If you're using Arduino to control the coil, why are you trying to implement a logical AND with BJTs?

Just keep the NPN transistor and write

if(A && B) digitalWrite(pin, HIGH);
else digitalWrite(pin, LOW);


in your code. A and B should correspond to the activation conditions of the IO pins in your original schematic.

No. You will have a high-side fail.

Figure 1. When VSS > +5 V (or whatever your micro-controller uses) there will be a base current leakage path and Q1 will turn on. Image source: High-side driver fail.

Figure 2. The solution to the high-side driver fail.

However, as Dmitry pointed out the AND function should be done in the micro-controller rather than externally.

• Do you want some feedback for this answer? If not, I'll delete this comment in 1 hour. – Harry Svensson Nov 22 '18 at 14:08
• Go ahead, Harry. – Transistor Nov 22 '18 at 14:09
• I like fig 1, that's spot on. Perfect part of this answer, a little bit sloppy because it's not the same load, but the problematic concept is the same. Fig 2 however is promoting an unnecessarily complicated circuit. The PNP doesn't have to be there, and again, slightly sloppy because it's not the same load. The more correct way would be to show an NMOS (logic level) + relay + flyback diode. Sure, I'm pedantic, but that's who I am. And then to be further pedantic, show flyback with resistor, flyback without resistor, but that's over the top. I would give +1 if it was only NPN or NMOS. – Harry Svensson Nov 22 '18 at 14:19
• @HarrySvensson, you are really out of line here. The question is whether upper pnp transitor will switch or not, and the answer clearly explains why not, never. The type of load has nothing to do with this whatsoever. Actually, it probably should be mentioned that the PNP will be always ON regardless of state of upper GPIO, and the circuit will still function, but not to the silly requirement of having two GPIO to control the relay. – Ale..chenski Nov 22 '18 at 15:53
• Transistor, you probably need to replace the "R2 with LED" in your illustrations with some more generic box and call it "load". Then there will be less questions and more focus on the issue with control (or lack thereof). – Ale..chenski Nov 22 '18 at 20:00

No this will not work. You will need another NPN to control the PNP transistor. Also the choise of the diode... use a bigger one lets say a 1N4007 or something like that