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

One's with a Vgs value of 3V or less for an Rds(on) value. This is the spec that says "given a gate voltage of this amount or more, the on-resistance will be this (or less)". Its the bit that is a guarantee of performance (most graphs in the datasheet are "typical" values, but FETs have a wide manufacturing spread when it comes to gate voltages, so "typical" really is not a guarantee.

Wow! I appreciate you taking the time to explain all this!

I will have to read the explanation several times to try and grasp it all lol!

I think I understand that transistors work via current and mosfets with voltage. So when you are picking a transistor to use, you are trying to pick one that will draw as little current as possible from the source (wemos pin in my case) to “turn on”. But it has to be able to supply enough current and voltage for whatever it is switching (relay in my case). So, you determine the resistor size (that connects to the transistors base pin) to limit the current draw from the source.
If you can’t use a resistor to limit the current draw to an acceptable amount based on the source (wemos output) data sheet, then you have to choose another transistor or go a different route? Maybe I’m getting closer to understanding?
Now, I am being difficult, as I stated in a previous post, I used a tip120 with the 2.1k resistor. Is that going to be a problem?
Will I be better or worse with it compared to the 2n2222, or is it a null point?

Is this what is referred to as a fly back diode?

Thanks all!

Sounds like you are getting this.


A TIP120 has a few problems.

Vbe for the TIP129 is about 1.6V
vs
0.8V for the 2N2222.


Vce(sat) for the TIP120 is higher than the 2N2222.


The 2N2222 should work fine with your relay.


Yes

When comparing transistors to MosFets, the latter is newer and in general more desirable technology.

In nearly case (and I'll get some flack on this) the MosFet is the more desirable component. They take almost no current from the Arduino (unless you are trying to switch them at 20kHz).
And they have excellent ON characteristics (i.e. when on there is very little voltage drop from Drain to Source).

The limitation to the MosFet (with regards to using them with the Arduino) is the Gate voltage. Many MosFets require a gate voltage above what a 5V Arduino can provide.
So when you pick a MosFet you must check the specification that defines the Gate voltage required to allow current to flow.

Often folks will find a MosFet that will work at the lower voltages. Typically you can find them with the capability to switch 10 or more amps. Purchase a bunch of them and use them for everything.

And get some SMD conversion PCBs too.

image

Yes, MOSFETS are easier to operate than BJTs because you don't need to worry about any base resistor value and such calculations. And for most (not all) real life applications you will be switching at no more than 1000Hz.


You can use this type of circuit with a higher Vth voltage rated MOSFET.

DISADVANTAGES OF THE ABOVE CIRCUIT:

  1. Switching time of MOSFET rises by a few ms.
  2. The source voltage needs to greater than 5V for Logic level MOSFET and more than 10V for Power MOSFETS.
  3. The logic is inverted. (Though you can use another NPN BJT to get the same logic).

To all the Forum users: Please tell me if I have made any mistake in the circuit. Suggestions are always welcome. :slight_smile:

Well, for low speed operations it will work. But for faster switching ON, the MOSFET needs a drive that can quickly charge its gate capacitor...so it needs a buffer or current source to drive it's gate instead of just the transistor's collector resistor. Similarly an active turn-off scheme will help with faster switching OFF.

I am assuming this just means get the ones that are already soldered to a board that is easier to solder/mount in hobby applications?

Also, how in the world are you testing 30 of these transistors so quickly? I assume you are just placing the transistors in some sort of header with the rest of the circuit soldered/or in a breadboard to test? What are you testing them with a DVM? Do you have a picture of testing setup? Just curious.

@Devanshu_Acharya,
I am a beginner to all of this, I am trying to understand the circuit.
"L" is the logic voltage?
is the "180" a diode?
Is what is circled in the picture below the relay in my case? (what is being switched on with the amplification of the mosfet?

What is the 10K resistor for? I think there was one in the same location in a schematic above. Someone may have answered it, but I couldn't find it when I looked back.

This is really interesting....

Thanks!

Sorry I just added picture I left off on last post.

The 10k resistor helps the MOSFET to turn off faster than it would without it by giving a discharge path to the gate capacitor. Actually that value appears to be a bit too high...but that depends on the gate capacitance and/or the voltage that it charges up to. Higher values need lower resistance for discharge to happen quickly. However too low a value might limit the voltage available to charge the gate capacitor especially if there is a current limit resistor present by voltage divider action. So turn on time will be affected.

You can find these boards on eBay unpopulated.

They are about 50 for $7.00

image

You solder a MOSFET or BJT (as desired) to a board.

Solder 3 header pins to the through holes.

Plug the board into your solderless breadboard when needed.


Make test circuits up on a solderless breadboard, you can test 33 transistors in just a few minutes.
Takes only seconds to measure strategic voltage points: Vbe, Vce, V(RC).


Takes 5 seconds to measure HFE using an Arduino component tester or a DMM that has a built in BJT tester.

Whatever does hFE have to do with it?

I thought we were switching things? :upside_down_face: Re #13.

As you are aware, HFE is a starting off point, perhaps an indication of the quality of the transistor and if it is a candidate as a switch.

Example let’s say a a transistor has a HFE of 10.
It might indicate this device is not the best for a switch application on the Arduino.

That being said let’s say the HFE of our 2N2222 was 100.

If 5mA goes into the base we can confirm ≈ 500mA could flow in the collector if the appropriate collector resistor was selected.
And you guessed it, during testing, this was indeed observed with the 33 transistors tested.

For transistor saturation action we want the Base to Collector to be forward biased as it was observed during testing.
For example Vce was 0.11V and Vbe was 0.73V. The measured Vbc voltage measured was 0.62V.
The transistor base to collector was forward biased. This resulted from selection of a 560 ohm resistor for the base using 3.3v as the input voltage, 0.11V for Vce also confirms the saturation.

Some times the rule of thumb using 10 times base current is suggested . . . this is almost always using an elephant’s foot.

As always mentioned, the EE must confirm the transistor is in saturation. This is done with either an oscilloscope or a DMM.
You would expect to see a very low Vce. If for example, you saw 3v Vce rather than the 0.11 volts, you know there is a problem . . .

What does HFE have to do with this ?
It tells you if you have a quality transistor, not much more than that.

But, you know all this stuff already.

hFE or hfe

Tom... :grinning: :+1: :coffee: :australia:

I remember covering H parameters many many years ago.

HFE, hfe, hre, hie, hoe, . . . what a wonderful time back then :nerd_face: .

http://dept.ru.ac.bd/apee/sites/default/files/principles%20of%20electronics%20ch-24%20h%20paratmetes.pdf

So why is it that high-current BJT transistors recommended for switching (low Vce(sat)) typically have a low-ish gain of 100, while a common 100mA BC547b is about 250.

A safe approach for mass-production?
Hobby-dudes can (should) measure Vce(sat) and can get away, if needed, with maybe 2% base current. I would stick with 5% though.
Leo..

For quick and dirty testing or circuits I use 10%. For production I would have to know much more about the device.


I consider a gain of 100 as quite high.

Of course, a transistor with a gain of 10 on a 3.3v controller would be a joke.


All high current transistors I’ve come across (example as used in 129VDC to 120VAC inverters) had high power drivers.
Side note, when they blew, metal and fiber glass all over the place. :grimacing:


As mention, the following is of utmost importance:

“ As always mentioned, the EE must confirm the transistor is in saturation. This is done with either an oscilloscope or a DMM.”.

Link, please.

Hfe is not the only parameter to be considered for switching. There are the various junction capacitances that affect both switching speed and RF performance. If a BJT is in hard saturation then its much harder to turn it OFF and this again affects speed. So additional means is needed to bring it out of saturation as quickly as possible or even not allowing it to saturate in the first place (as in ECL).

That said for general purpose use as long as the BJT has a Ft of 1 MHz it can be used for switching. hfe determines how much base drive is needed to switch, not necessarily how fast it can switch.