Using 2n2222 to switch relay on/off with 3.3v


I have read many threads about using transistors to switch relays of larger voltages on with microcontrollers, but most of them end without a solution, or I am not smart enough to understand the responses given.
I am trying to switch a rf6105-12v-c (what I am calling a relay?) with a 2n2222 transistor.
I did this same exact thing on another project, but I used a TIP120 transistor with a 2.1K resistor and arduino uno to do the switching, and it is still in use now.
I didn't have any TIP120's on hand, so yesterday I thought I would try the 2n2222 to do the exact same thing. I had two of the transistors with a 2.1K resistor switching two separate relays and it worked. I was able to engage the linear actuator via 3.3v from wemos board - transistor - relay several times without any problems. I mounted the actuator and it stopped working.. I can't get it to work again.
I have confirmed that the relays are still good, but I can't get it to work with the transistors. I assume the transistors went bad or I shorted them out when mounting it. Did I wire them up correctly? Is my resistor too large/small?

The relay engages when I get 0v or ground going to the point that the "collector" is going to in the diagram. All grounds are connected together.
I want the relay to engage when the pin d1 goes high. (3.3v). The relay is controlling a 12v linear actuator.

Please use 2nd grade terminology for me. I am stupid.

Thanks!

Firstly the RF6105-12V-C relay seems to be a high power contactor, switching 150A. This means the coil will be powerful and take a lot of current - but I can't find any proper data for it.

So you need to measure the resistance of the relay coil and figure out the current it needs (I = V/R).

Secondly when switching a relay you must have a free-wheel diode across the relay coil, as in this tutorial: https://www.electroschematics.com/arduino-control-relay/

You'll see an 1N4007 diode in that circuit. Without a diode in this position you'll simply instantly fry the transistor the first time it switches off due to the inductive kick-back - the diode tames this.

A 2N2222 might or might not be able to handle the current of this relay, but note the base current needs to be at least 5% of the load current for it to switch fully - you need to find out the Wemos board's pin current handling ability to judge this.

2.1k resistor does sound rather high though, that's only 1.4mA from a 3.3V drive voltage (3.3V - 0.6V) / 2100 = 0.0014.

I would expect something more like 100 to 200 ohms (assuming the Wemos pins can handle the current).

My read is you have a 12 VDC coil relay capable of switching 14 VDC @ 150 Amps. Problem is I can't find the coil current for the relay? The current for the coil will determine the transistor base resistor value. Also you want a flyback diode across the relay coil. Carhode side to positive. Anyway can you find a data sheet for the relay that includes coil current?

Ron

I looked for and couldn’t find this info either. Not that I would know how to calculate it, but to provide here. Is there a way to calculate a worst case scenario? Lol again I know I’m stupid. It may be rated for 150 amp, but it is WAY over kill for the application I’m using it for. It is simply running a 12v actuator that is lifting about a 15 lb door. I am not worried about efficiency if that matters.

So this should go from the collector leg to the output leg of the relay (12v)?

Thanks!

It goes across the relay coil, cathode to the +ve supply. The diagram shows this.
Perhaps this is what you meant, but the important point is it is across the inductive winding of the relay where it needs to be.

Like this?

Personally, I've switched to MOSFETS. Generally, they are either on or off. The math of calculating the base resistor to fully turn on the transistor was always a challenge.

Here's how I controlled a small 12V fan from a Wemos D1 Mini GPIO pin.


You still need to determine the current drawn by the relay coil in order to make sure the MOSFET can handle it.

I would have mentioned MOSFETs once it was established 2N2222 wasn't going to work - the problem is 3.3V rated logic MOSFETs are nearly all surface mount.

Thanks! This is what I am looking for how to make these type projects simpler for me. I am trying to understand this:
To get a transistor to completely “close” and allow full current through, it must be “saturated”? Am I using that term right?
In order to get it saturated you must calculate which resistor is required based on the current draw, voltages, etc?
If you use a resistor with that is too high, you do not get the full potential of the transistor, if you use a resistor too small, their is potential to damage the source of the base current (wemos pin in my case).

Am I even close?

With a mosfet, it is either fully closed (allowing current through) or opened (generally as you say)?

In your schematic, you still use a resistor with the mosfet. Is the value of the resistor not as important?

Thanks!

I don’t understand? The way to connect them to the perf board is difficult?

Thanks!

Your relays look to be typical automotive type but of a much higher current handling ability. Give or take these relays have about a 75 Ohm coil and coil current in the neighborhood of 160 mA. The 2N2222 should do fine driving one. A 2N7000 MOSFET has a maximum continuous drain current of 200 mA. This is why it would be nice to know the coil current.

Using a 2N2222 we normally assume a base current of 1/10th the collector current. So roughly winging it with some overkill figure a collector current of 200 mA so a base current of 20 mA. The emitter base voltage drop is 0.7 Volts. Figure your WEMOS will apply 3.3 volts.

R=(V-Vbe)/Ib=(3.3-0.7)/0.020=130 Ohms so I would look for the next highest common value of 150 Ohms and use a flyback diode as suggested with it across the relay coil and cathode (band) side to positive and anode side to common ground side of the coil.

Ron

For instance this sort of package is common: https://uk.farnell.com/infineon/bsr802nl6327htsa1/mosfet-n-ch-20v-3-7a-sc-59/dp/2212883

Yes, basically that's right. Set the base current to be 5 to 10% of the collector current for a BJT. With a darlington its easy as the base current only needs to be about 0.1% of the collector current.

MOSFETs need the right gate drive voltage to be fully on. This is given in the datasheet with the on-resistance, for instance "Rds(on) = 0.01 ohm at Vgs = 4.5V" or something like that. Ignore the threshold voltage, its not relevant.

Wow! Lots of helpful good info!
But I’m stupid so I still have questions:

If I used the same equation to calculate what would be needed for say a different transistor, the only thing that would change is the “.7” voltage drop?
If I calculated it for the tip120 (a darlington) it would change because you would use 1/100 instead of 1/10 for base draw in comparison to collector?
2. With a mosfet, if i find a voltage that the gate will open/close with the 3.3v that my wemos can supply, and it can handle the amperage draw of the relay (which is unknown). It will work without the worry of getting the resistor amount right?

On one yes, the formula used is pretty generic and based on the base emitter junction of a everyday switching transistor application. It can get more complicated but what I used would do for now. Problem is if we don't turn the transistor fully on (into saturation) for the load the transistor screams for mercy as it cooks.

With a MOSFET it's a different game. There are logic level MOSFETs designed around having a gate voltage of 5.0 volts. The problem is how well they turn on at 3.3 volts? This is where we start looking at data sheets with their charts and curves. Like anything else in electronic design and other design we choose a part based on intended application and environment it will function in.

Ron

So, the 3.3v wemos is a real problem when dealing with mosfets... ?

I used a wemos to energize a ssr (ac volt output) and I was advised to use the 5v pin on the wemos to run to the ssr and when I wanted to energize it, have the digital pin go LOW. Would this be an option with a mosfet?

Place 5v on the gate all the time, and when you want to activate it have the digital pin (connected to the drain?) go LOW when you wanted to activate it?

Thanks!

MarkT is correct, there are few logic level MOSFETS that work at 3.3V (gate), and most are surface mount.

I use the 2N7000 with 3.3V logic and ignore the higher Drain-Source resistance (which limits it's current capacity). I use it to power loads of less than 50 mA.

The IRL540 is better than the 2N7000 for higher loads. The specs show a
VGS = 4.0 V and a resulting Drain-Source resistance of 0.11Ω., but I am not planning to draw 20Amps through the circuit. (The IRL540 is rated at 20 Amps continuous).

The gate transistor is needed to reduce the inrush of current when the gate receives a logical high. (The gate-source capacitance the problem here, but since we aren't likely to be working in the MHz switching frequencies, it can be generally ignored). The value computation is dependent on the speed of switching you need. But we generally aren't working in the MHz frequencies, so just about any resistor value will work for us. Anything from 1K to 10K will work.

The gate-source resistor is to keep the gate below the turn on threshold when there is no input. It's value is not critical in low-speed switching. I use 10K because I have a lot of them.

There is some discussion where to put the gate resistor. My drawing, above, is what Toshiba recommends. This does reduce the data voltage at the gate slightly (it is a voltage divider) which is why some put the pulldown resistor on the other side of the gate resistor. I've done both and never seen any difference in operation.

Again, all of this discussion is just blah, blah, blah until you know what the relay coil current is.

Can the coil resistance be checked even if it is already soldered to the board and connected with other electronics? Or does it have to be completely isolated to check resistance?

Depends on the circuit surrounding the coil.

However, most relay coils are low resistance, compared to other components, so measuring the resistance with a DMM can work.

If there is a snubbing diode across the coil, reverse the DMM leads and record the largest value for the coil resistance.