Switching 12v magentic lock with NPN PN2222

Is this simple NPN as a switch a proper design? Do I just replace that cloud area on the low side of the lock with the NPN as shown?

I have a 12v magnetic lock for a gate that I'd like to switch via Arduino. There is currently a simple 12v transformer that is driving the lock.

Sorry for the hand-drawn...

Should the 12v ground and the 3.3v ground be tied together?

[edit - the arduino voltage is actually 3.3v rather than 5v]

One of my gate locks runs at 300mA while the other uses 450mA so using FAQ | Transistors 101 | Adafruit Learning System I calculated the resistor values to be 0.9 k-ohm and 0.6 k-ohms respectively. Using a 3.3v flavor of the controller.

HeneryH:
Should the 12v ground and the 3.3v ground be tied together?

Yes because the output of your arduino needs a way home.

HeneryH:
One of my gate locks runs at 300mA while the other uses 450mA so using FAQ | Transistors 101 | Adafruit Learning System I calculated the resistor values to be 0.9 k-ohm and 0.6 k-ohms respectively. Using a 3.3v flavor of the controller.

Unfortunately that guide is bogus - the gain of a transistor is not relevant for use as a switch, since the
gain applies to active mode, whereas used as a switch a BJT is either cut-off or in saturation, and gain
is not applicable to either.

Generally, with most BJTs, you need 5% to 10% of the collector current to go to the base to guarantee
full saturation (low Vce). The transistor behaviour is different in saturation as the base-collector
junction is forward biased. Use 82 ohm resistor on the base for 0.45A load and 3.3V, that's going
to provide about 20 to 25mA base current which is only just enough. (the Arduino output impedance
is about 40 ohms already, 82 + 40 is about 120, (3.3-0.7)/120 = 0.025 roughly

Your resistor values will result in the Vce being 1V or more I suspect, causing the transistors to run really
hot...

I don't understand the diagram of the lock, please post link to datasheet/product page for all the hardware so we can understand what you actually have. In particular its not clear why each side is powered.

MarkT:
I don't understand the diagram of the lock, please post link to datasheet/product page for all the hardware so we can understand what you actually have. In particular its not clear why each side is powered.

Sorry for the confusion of how I drew the as-is vs the to-be versions next to each other. I cropped out the as-is and just left the to-be in the image above.

Two locks are
https://www.locinox.com/en-gb/locinox/eu/locks/swing-gates/lekqu4
http://www.allgateoperatormanuals.com/glock_installation.pdf

And I should have said you need a free-wheel diode across the load, otherwise you'll blow up
the electronics the first time you switch it off. 1A diode across the lock winding, cathode to the +ve supply.

Your 12V supply is DC? That's assumed, but I'd better ask.

MarkT:
Your 12V supply is DC? That's assumed, but I'd better ask.

yes, dc.

I'll research more on the resistor value.

Thanks for the feedback. Many of the tutorials I have seen used the 5v power for the motors but in my case I need the 12vdc for the gate.

Hope it doesn't fry!

You do need to take account of hFE , to calculate the base curent you need to drive the transistor into saturation with your proposed collector current. So if hFE is 100, and your collector curent 1A, you need at least 10mA base current :

“hFE is an abbreviation, and it stands for "Hybrid parameter forward current gain, common emitter", and is a measure of the DC gain of a junction transistor. “

hammy:
You do need to take account of hFE , to calculate the base curent you need to drive the transistor into saturation with your proposed collector current. So if hFE is 100, and your collector curent 1A, you need at least 10mA base current :

“hFE is an abbreviation, and it stands for "Hybrid parameter forward current gain, common emitter", and is a measure of the DC gain of a junction transistor. “

Time to review how a transistor works.
Hfe is not relevant for switching (when collector voltage is LOWER than base voltage).
See post#3.

A 2N2222 basically can't be used to switch 450mA with a <=7mA 3.3volt pin.
A very low level logic fet is the best option, a TIP120 or smaller darlington is second best.
Leo..

Oh dear ... from a quick google:


The actual transistor used as a switch is not critical in these applications. Virtually any general purpose NPN or PNP transistor can be used as a switch. All that is needed is to know the minimum HFE and the power dissipation of the transistor. While most all transistors in a TO-92 case will have HFE’s of at least 100, many power transistors in TO-220 cases often have an HFE no greater than 25. It is essential to know the HFE or Beta of a transistor, so that we can have a large enough base current to achieve saturation. If a power transistor is used to turn on a high current device, it may be necessary to use another lower current transistor switch to drive a transistor switch used in a high current application.”

hammy:
You do need to take account of hFE , to calculate the base curent you need to drive the transistor into saturation with your proposed collector current. So if hFE is 100, and your collector curent 1A, you need at least 10mA base current :

“hFE is an abbreviation, and it stands for "Hybrid parameter forward current gain, common emitter", and is a measure of the DC gain of a junction transistor. “

My post #3 covers the correct way to set the base current to avoid burning out a switching transistor....

@hammy,

Remember, the data sheet is your friend (although sometimes it seems to talk a different language).

For the 2N2222A the datasheet I found P2N2222A Figure 4 indicates:

at nominal for a 500 ma collector current you need 50ma base drive to obtain a Vce of 0.2 volts. Just as MarkT said. hfe does not come (directly) into the equation for this mode of operation.

This condition will result in power dissipation of 0.05 * 0.7 + .450 *0.2 = 1/8 watt not too bad but one still needs to get the 50ma base current from somewhere.

IMHO a small logic level FET would be a much better choice. I understand in instances like these often the OP had access to a component that is close but not a good fit. So if I were the OP I would order the right parts and at the same time try with what I had.

I’d agree with what you are saying there JohnRob from that example .
I have always used my method and it’s quoted a lot in examples in internet , but I do tend to add a bit more as insurance and it’s served me well . Esp as often you don’t see all the data when choosing your transistor from a supplier.
Yours is a good explanation, I’ll look at that again.

I guess i would use a ULN2803 instead, 8 ports of open-collectors that you could bridge even i think they go up to 500mA each and are driven by a logic input.

Yes, and with built-in freewheel diodes too. But you get more heat, as Vsat is quite a bit bigger
for a darlington.

The ULN2x03 is essentially obsolete due to poor performance. There is a FET variant, but I keep forgetting the reference.

The collector current rating of the PN2222 appear adequate for this application, but the saturation voltage might be marginal.

However if you use the resistors MarkT cites in reply #3 to provide 25 mA base drive, the maximum you could sensibly source from an Arduino output, then figure 4 in that reference suggests the saturation voltage will be less than 300 mV and the power dissipation (remembering that these locks must be powered continuously to hold secure) will be less than 150 mW which is comfortably within the transistor rating.

MarkT:
Yes, and with built-in freewheel diodes too. But you get more heat, as Vsat is quite a bit bigger
for a darlington.

you are saying that it will not be sufficient and that it will get to hot ?? if in doubt check the datasheet, if one pin is not enough we can use more of them...

Looks like a few of us should write some emails to Adafruit and take them to task for that page.