# Is it safe to drive a MOSFET from an output pin of a microcontroller?

I have used commonly-available BJTs such as the 2N2222 and 2N3904 as switches by operating them in "saturation mode" from my MCU. I believe, however, that for these sorts of applications, a MOSFET is a more appropriate device. I have a few questions, however.

1) Does a MOSFET have a "saturation mode" like the BJT does? Is this "saturation" achieved by simply providing a high enough voltage on the base that the MOSFET is completely "on"?

2) Is it safe to drive the MOSFET directly from the MCU? I understand that the gate of the MOSFET behaves like a capacitor, and therefore draws some current while "charging", and then none thereafter. Is this charging current high enough to damage the MCU pin? By placing a resistor in series with the gate, I can protect the pin, but this will slow down the switch, possibly resulting in high heat dissipation by the MOSFET?

3) What is a common "hobbyist" MOSFET suitable for various low-power situation? I.E., what's the MOSFET equivalent to a 2N2222 or 2N3904?

• "more appropriate" sounds silly to me. Usually BJTs are cheaper, so I'd use a FET only if a BJT won't do. – starblue Apr 15 '11 at 6:07
• I've generally done the opposite: use a MOSFET unless I need a BJT. They're both cheap. The power wasted by a MOSFET's R_DSON is usually less than from a BJT's V_CESAT. You only pay power to switch a MOSFET, not to keep it on, which reduces power dissipation in both the transistor and the part that drives it, especially if switching is infrequent. MOSFETs usually go all the way to the rail because there's no V_CESAT. The downside is that a MOSFET doesn't pull a constant amount of current across the entire edge, since it looks like a resistor; this slows down switching a capacitive load. – Mike DeSimone Dec 4 '11 at 15:50

Many power MOSFETs require a high gate voltage for high-current loads, to ensure that they are fully turned on. There are some with logic-level inputs, though. The data sheets can be misleading, they often give the gate voltage for 250 mA current on the front page, and you find that they need 12V for 5A, say.

It's a good idea to put a resistor to ground on the gate if a MOSFET is driven by an MCU output. MCU pins are usually inputs on reset, and this could cause the gate to float momentarily, perhaps turning the device on, until the program starts running. You won't damage the MCU output by connecting it directly to a MOSFET gate.

The BS170 and 2N7000 are roughly equivalent to the BJTs you mentioned. The Zetex ZVN4206ASTZ has a maximum drain current of 600 mA. I don't think that you will find a small MOSFET that can be driven from 3.3V, though.

• the 2N7000 has a maximum current of 200mA, where the 2N2222 has a maximum current of ~600mA. is there something in that neighborhood that is easy to drive with a 3.3v MCU? – Mark Apr 14 '11 at 20:53
• What number am I looking for to determine whether 3.3V is enough to turn the MOSFET on? Phillips' 2N7000 has a VGS(th) (gate-source threshold voltage) of 2V typ, does that mean that 2V would turn the MOSFET completely "on", or just barely "on"? – Mark Apr 14 '11 at 21:19
• @Mark Barely. It's like just passing above the threshold voltage on a BJT. Unfortunately with the MOSFET you do not have the exponential characteristic. – jpc Apr 15 '11 at 2:33
• The thing to remember when shopping for MOSFETs is not not prematurely limit the V_DS or I_D when searching! These numbers are much higher for FETs than you're used to seeing for BJTs given a certain driven load. Note how the AO3422 (V_DS=55 V, I_D=2.1 A) is much higher than the specs for the similar 2N2222 (V_CE=50 V, I_C=0.8 A); this is due to efficiency! The reason you don't see "typical MOSFETs" like you do for BJTs or diodes (1N4148 etc.) is that MOSFETs came along later, when there were more companies making them, and there was much less motive to copy competitors' standard parts. – Mike DeSimone Dec 4 '11 at 16:18
• @MikeDeSimone: "The first parameter to check is V_GS(th), like Mark noted. It's roughly equivalent to V_IH for a CMOS input if n-channel, or V_IL for a p-channel. In other words, drive past that value." No, no, no. All V_GS(th) means is that you get past a specified current. The MOSFET isn't considered "on" until the device has completely resistive behavior over a specified range of currents. This requires higher voltage than V_GS(th), and is not usually specified until the guaranteed Rdson specs, somewhere in the 4.5V-10V range (sometimes at lower voltages). – Jason S Aug 17 '15 at 22:19

It is safe - in general - and it will work if you select a "logic level" MOSFET. Note that "logic level" does not seem to be an exactly standardized term, and it won't necessarily show up as a parameter in the parametric search at the vendor sites, nor will it necessarily show up in the data sheet. However, you will find that logic-level MOSFETs often have an "L" in the part number, ex: IR540 (non logic level) vs. IRL540 (logic level). The big thing is to look in the data sheet and check the VGS(threshold) value and look at the graph that shows current flow vs VGS. If the VGS(threshold) is like 1.8V or 2.1V or so, and the "knee of the curve" on the graph is at around 5 volts, you basically have a logic-level MOSFET.

For an example of what the specs on a logic-level MOSFET look like, check out this datasheet:

http://www.futurlec.com/Transistors/IRL540N.shtml

Figure 3 is the graph I was referring to.

All of that said, I see that a lot of people still recommend using an opto-isolator between the micro-controller and the MOSFET, just to be extra safe.

Re: saturation: yes, but it's confusingly not called saturation (which actually corresponds to the linear region in bipolar transistors). Instead, look at the datasheets and the rated on-resistance Rdson, which is specified at a certain gate-source voltage for each part. MOSFETs are usually specified at one or more of the following: 10V, 4.5V, 3.3V, 2.5V.

I'd put two resistors into the circuit: one from gate to ground, as Leon has mentioned (actually I'd put it from the MCU output to ground), and another between the MCU output and the gate, to protect the MCU in case the MOSFET has a fault.

More discussion on this blog entry.

As for what MOSFET to use, there really isn't a parallel to the 2N3904/2N2222.

2N7000 is probably the most common & cheapest FET out there. For other jellybean FETs, I'd look at Fairchild FDV301N,FDV302P,FDV303N,FDV304P.

For the next step up (higher power level), I'd look at IRF510 (100V), or IRFZ14 (60V), both in TO-220, though these are basic FETs spec'd at 10V gate-source. Logic-level FETs (IRL510, IRLZ14) have Rdson specified at 4.5V gate-source.

• The resistor from MCU pin to gate is also used to slow down the switching edge, to reduce ringing, overshoot, and EMI. 10 ohms is a typical value. – Mike DeSimone Dec 4 '11 at 15:55

In answer to question 3, I found the Fairchild FQP30N06L is ideal for driving a high power device from a MCU at logic levels. It's not cheap (0.84 GPB) but great for lazy n00bs like me. I'm using them for supplying 12V RGB LED light strips.

Some stats:

Vdss Drain-Source Voltage: 60 V
Id Drain Current: Continuous (TC = 25°C) 32 A
Continuous (TC = 100°C) 22.6 A
Vgss Gate-Source Voltage: ± 20 V
Vgs(th) Gate Threshold Voltage: 1.0--2.5 V


Therefore, Raspberry Pi's 3.3v is above the 2.5V upper Gate Threshold, which will ensure that the drain is fully open.

• Don't drive this directly from an MCU. The turnon/turnoff time will be very long due to the gate capacitances, and you're not protecting the MCU from any faults. – Jason S Aug 17 '15 at 22:12
• More seriously, just because 3.3V is above the gate threshold, that does not means the switch is fully on. All it means is that the current is guaranteed to be above a given threshold (250uA for the FQP30N06L). The FQP30N06L is designed to be driven from voltages of at least 5V, which is the minimum voltage that they specify on-resistance. Any lower than that, and you have no guarantees whatsoever of device behavior beyond the 250uA current of the Vgs threshold. – Jason S Aug 17 '15 at 22:14
• Hi JasonS, forgive my ignorance. I don't see in the specifications where 5V is given as a minimum. The graph data shows that ~3.3V on the gate allows for >10A on the drain @25V, which is ideal for my purposes (5A @ 12V). For protection, I've put a 10KΩ resister between Gate and Ground and intend to put a similar sized resister between the MCU pin and Gate. Will this be sufficient? – Alastair McCormack Aug 18 '15 at 9:16
• "The graph data shows..." Characterization graph data in a datasheet is almost always a representation of typical performance, not worst-case. In other words, it's the mean behavior, not the extreme, and you can't rely on it being valid for all devices. The reason they include it at all is that the relative behavior (current goes up with increasing gate voltage and increasing drain voltage) is universal... you just can't rely on the numbers. – Jason S Aug 18 '15 at 13:32
• Look at page 2 ("On Characteristics") -- it gives you two specs for Rdson with Vgs = 10V (35mohm max) and Vgs = 5V (45 mohm max). As far as protection... well, see my article embeddedrelated.com/showarticle/77.php -- pulldown resistor can be fairly high, usually 100K - 1M is fine. But you really need a gate driving circuit from 3.3V logic. It doesn't have the voltage necessary to guarantee that the FQP30N06L will be turned on. Some devices may have quite a bit higher Rdson at 3.3V (or may still be in the constant-current range) and overheat as a result. – Jason S Aug 18 '15 at 13:39