The MOSFET as Switch

About the post

Transistors are often used as switches in the world of microcontrollers. Especially with high currents to be controlled, the choice often falls on a MOSFET. In principle, MOSFETs are very easy to handle, but there are still some things to consider when working with them. First of all, there is the question of which parameters to pay attention to in order to select the right MOSFET. Another question is which additional components are needed. Do I need a series resistor at the gate? Do I need a gate driver? The article should help to answer this question. 

The following topics will be covered:

What is a MOSFET?

TO-220 / TO-92 MOSFET
TO-220 / TO-92 MOSFET

On the net you can find many articles explaining the structure and working principle of MOSFETs, e.g. here on Wikipedia. That’s why I’ll only go into the bare essentials here.

The term MOSFET stands for Metal-Oxide Semiconductor Field-Effect Transistor. The MOSFET has three connectors, which are called gate, drain and source. With the voltage between gate and source, you control the current flow between source and drain. Normally, the gate is on the left, drain in the middle and source on the right when you look at the labeled side of the MOSFET. 

There are n-channel and p-channel MOSFETs. The n-channel MOSFET opens when the voltage at its gate in relation to its source exceeds a certain positive threshold. For the p-channel MOSFET to open, there must be a voltage at its gate that is negative relative to its source. You use the n-channel MOSFET on the GND side, the p-channel MOSFET on the positive side of the supply voltage.

n-channel vs. p-channel MOSFET
n-channel vs. p-channel MOSFET

I will focus on the n-channel MOSFETs in this post.

MOSFET vs. bipolar transistor

Anyone who speaks of a transistor usually means a bipolar junction transistor (BJT). But since MOSFETs also belong to the large family of transistors, I have to distinguish them by name here.

BJTs, like MOSFETs, have three connectors. And with them, too, the current flow between two of the connectors, namely collector and emitter, is controlled via the third connector, the base. However, they differ (among other things) in these aspects:

  • In the BJT, current flows from the base to the emitter. This controls the current flow from the collector to the emitter. The bipolar transistor is therefore current controlled. In contrast, the MOSFET is voltage controlled.
  • The switching speed of the MOSFETs is higher than that of the BJTs.
  • MOSFETs are more expensive.
  • MOSFETs are suitable for higher currents.
  • The BJT starts to conduct at a base-emitter voltage of about 0.7 volts. The MOSFET, on the other hand, usually requires gate-source voltages of 1 to 4 volts.
  • The MOSFET has a significant parasitic capacitance. More about this later.

Minimal circuit

Let’s assume you want to switch a component that is operated with 5 volts. Furthermore you need a current that exceeds the limit of an I/O pin. This would be for example 20 mA for the Arduino UNO. On the other hand the current should be only so large that it can be provided by the 5 volt output of the microcontroller board. For USB operation, this is usually 500 milliamps, minus 50 milliamps for the board and minus what the I/O pins provide in total. In this case, the circuit can be simple: 

Minimal circuit with a MOSFET

The load resistor R_L represents the device you want to switch. The question, if you need a series resistor, will be discussed later. Mostly you will be able to omit it. 

I tried the circuit with an IRL520 MOSFET. Among others, a 0.2 Watt LED (40 mA) was used as load.

For the MOSFET to lock reliably, it must be pulled to GND level. With the above circuit this is done when setting pin 9 to OUTPUT/LOW. The safer variant is the use of an additional pull-down resistor (47 kΩ).

For higher current requirements or higher voltages, you will need to supply the load with a separate power source. If you use a load that has a coil, such as a motor or an electromagnet, do not forget the obligatory free-wheeling diode.

Not so minimal MOSFET circuit
Not so minimal MOSFET circuit

Selection criteria for MOSFETs

There is a huge range of MOSFETs, which does not make the selection any easier. In addition, the data sheets are quite confusing for non-electronics engineers, since the list of specified properties is long. In the following, I will go into the most important criteria.

Logic level MOSFETS

Data sheet spec of a logic level MOSFET

If you want to control a MOSFET with 5 or even 3.3 volts gate-source voltage, you should use a logic level MOSFET. Whether it is such a MOSFET is usually written on the first page of the data sheet, like in the example on the right. Also, the RDSON value (explanation follows) for the logic level MOSFETs is specified at 5 volts or lower, not 10 volts as is usually the case. Another indicator is a low “Gate-Source Threshold Voltage”. This is the minimum gate-source (GS) voltage at which the MOSFET starts to conduct.

For logic level MOSFETs the value is often between 1 and 2 volts, otherwise it tends to be 2 to 4 volts.

Many MOSFETs have a label according to the scheme “IRFxxx” or “IRLxxx”. With the “IRLs” you can usually assume that it is a logic-level MOSFET. However, it is not certain that an “IRF” is not a logic-level MOSFET. You can find more shortcuts here on This is a German article, but you should be able to understand the tables.

Maximum drain current

The data sheets of the MOSFETs specify the maximum drain current ID, as here for the IRL520:

IRL520 data sheet: maximum I drain

However, the maximum ID depends on the gate-source voltage. You can find diagrams like the following in the data sheets:

MOSFET characteristic: I drain over V drain-source
I Drain over V Drain/Source

This is not as complicated as it may seem. Each of the curves indicates, for a given gate-source voltage, how the current ID varies with the voltage between drain and source. The point is:  For each gate-source voltage, there is a saturation range for ID. Maybe it is more understandable this way: You have set a certain gate-source voltage in the circuit on the right, at which MOSFET conducts. Now you continuously increase the voltage Uvar. ID increases and so does the voltage drop across the load and across drain-source. When ID finally reaches the saturation region, the voltage drop across the load remains constant (U = R ⋅ I) and any additional increase in Uvar drops across drain source without further increase in current.

Static Drain−Source On−Resistance RDSON

Another important selection criterion is the “Static Drain−Source On−Resistance” RDS(on). This is the resistance that drops across drain-source when open (“on”). An ideal switch has infinite resistance when off and zero resistance when on. In this respect the MOSFET is not a switch at all, but a controllable resistor! RDS(On) is comparatively small, but not negligible (data again for the IRL520):

MOSFET parameter RDSON - specification in data sheet
Data sheet RDSON (IRL520)

It should also be noted that RDS(On) is not constant, but increases as the gate-source voltage decreases.

At high currents, RDS(On) becomes noticeable through power losses, i.e. the transistor becomes hot. Here a small calculation: The gate-source voltage at an IRL520 is 5 volts. RDS(On)is therefore 0.27 ohms. Let the current be 5 amperes. Thus, the power loss is:

P = U_\text{DS}[\text{V}]\cdot I_\text{D}[\text{A}]\; = R_\text{DS(On)}\cdot  I_\text{D}\cdot I_\text{D} = 0.27\cdot 5 \cdot 5 = 6.75[\text{W]} 

Making things worse, RDS(On) increases with temperature:

MOSFET IRL520: RDSON vs. Temperatur
RDSON vs. temperature for the IRL520

This easily doubles the power dissipation or even more.

The RDS(On) value of the IRL520 is quite high at 270 mΩ. There are MOSFETs with significantly lower resistances. The IRLB3034PbF, for example, is at the low end with a maximum of 1.7 mΩ at 4.5 volts gate-source voltage. The power loss is correspondingly lower. 

Further considerations

Do I need a heatsink?

Due to the potentially high power dissipation, the question arises whether it is necessary to provide the MOSFET with a heatsink. To estimate this, look for the value for RθJA (Thermal Resistance Junction-To-Ambient) in the data sheet:

In this case (IRL520) the temperature increases by 62 degrees per watt. With the 6.75 watts calculated in the above example, you would initiate the GSA (greatest supposed accident)!

In the data sheets you will find the maximum temperature TJ (J = Junction) for the MOSFET. A typical value is 175 °C. Considering the maximum expected ambient temperature TA, the maximum allowable power loss is: 

P_\text{max}=\frac{T_J-T_A}{R_{\Theta J\!A}}

As already mentioned, the temperature dependence of RDS(On) must be considered when calculating the power loss. If you install your circuit in a closed case, then the ambient temperature also increases. In addition, you should not work permanently at TJ, but stay at least 30° below it.

These are all only estimations. You are responsible for the interpretation – I do not take any liability!

Do I need a series resistor for the gate?

In some circuits you will find series resistors for the gate of the MOSFET, in other circuits you do not. Do you need them? I found many controversial discussions about this on, e.g. this one here (very entertaining, but unfortunately in German). There are two aspects to this: One is unwanted electrical oscillations that can be caused by a fast charging of the gate, the other is the protection of the microcontroller. To be clear, my conclusion is: as long as you don’t work with very high PWM frequencies in combination with a high gate capacitance, you can omit the series resistor. But one thing at a time.

Basis vs. gate resistor

First of all I want to come back to the difference between the gate of a MOSFET and the base of a BJT. The base resistance of the BJT is essential because only ~0.7 volts drop between base and emitter. Higher voltages lead to practically uncontrolled currents.

The MOSFET, on the other hand, is voltage controlled. No current flows from gate to source. However, the gate has a certain capacity and therefore behaves like a capacitor. And to charge this capacitor, a time-limited current flows.

Gate resistor experiments

For this purpose I have carried out a few experiments. Starting point was this simple circuit:

The IRL520 was used again as MOSFET. The 5 volts were provided by a laboratory power supply. A 10 kΩ resistor served as load, thus a very small load. With this circuit a pull-down resistor is needed, otherwise the gate would have an undefined potential. I soldered the contact to the gate, because connectors on the breadboard produced noticeable resistances. With the oscilloscope I observed the gate-source and the drain-source voltage when closing the switch.

MOSFET experimental setup
Experimental setup

This was the result without series resistor:

Without series resistor – yellow: gate-source voltage, blue: drain-source voltage

It took about 40 nanoseconds for the gate-source voltage to reach the applied voltage. The drain-source voltage drops to ID x RDS(On) in less than 3.6 nanoseconds when the gate-source threshold voltage is reached.

There is another relevant specification in the data sheet, namely the “Total Gate Charge”. This is the maximum charge that must flow into the gate to fully charge it. I didn’t apply the conditions given in the data sheet for this value, but I also just want to make a rough calculation. 

Total Gate Charge of the IRL520

Thus, up to 12 nanocoulombs flow in about 40 nanoseconds. Current is charge per time, so the result for the current is:


For the Arduino UNO a limit of 20 milliamps is given for the I/O pins. In the datasheet of the ATmega328P the absolute maximum is given with 40 milliamps. So, with the 300 mA we are far above that.

In another experiment, I connected the MOSFET with an Arduino I/O pin. For this, I soldered the connection cable directly to the Arduino pin to keep contact resistances as small as possible:

Circuit without series resistor, but with Arduino

In this case, charging the gate takes 120 nanoseconds. The Arduino pin cannot charge it as fast as my lab power supply. The calculated current is 100 mA, which is still well above the specification. 

So will I destroy my Arduino eventually? The prevailing opinion is no. If this stress level is in the nanosecond range, the Arduino can handle it.

What happens using PWM?

With pulse width modulation, the microcontroller pin must load the gate at the PWM frequency. The analogWrite() function provides a PWM signal whose frequency depends on the MCU board and the pin. For the Arduino boards, the frequency is ≤ 1000 Hz. At 1000 Hz, the average current (still related to the IRL520) would be:

I = \frac{12 \cdot 1000\;[\text{nC}]}{1\;[\text{s}]}=12\;[\text{µA}]

This is also no problem:

analogWrite controlled IRL520, yellow: gate-source voltage, blue: drain-source voltage

If you need faster PWM frequencies, it can become problematic at some point. This is because you will actually reach the range where you also reach the specification limits for the continuous current. At 1000 kHz, the current is already 12 mA. And moreover, there are MOSFETs with even higher gate capacitances. In such cases you can use a MOSFET driver. But we will come to that.

What does a series resistor at gate?

If you place a resistor in series to a capacitor, the capacitor will charge slower. I have tested this with a 100 Ω and a 1 kΩ resistor in series to the gate:

Series resistor: 100 ohms
Series resistor: 1 kohms

With the 100 Ω resistor, the charging time of the gate increases from 40 to about 440 nanoseconds. Accordingly, the current to be provided is lower and the signals are cleaner. With the 1 kΩ resistor, the charging time is already about 3.6 microseconds.

Why using zener diodes?

In many MOSFET circuits you see Z-diodes between gate and source and/or between drain and source. What is it good for?

A zener diode acts like a normal diode in forward direction. In reverse direction it blocks up to its breakdown voltage and then becomes a good conductor. A zener diode is therefore a kind of overpressure valve, only for voltages. They are available with a wide range of different breakdown voltages.

MOSFETs react allergically to overvoltages at the gate. They can be destroyed relatively easily. Therefore zener diodes are well suited to protect the MOSFET or also to avoid voltage peaks at drain. The breakdown voltages must of course be adapted to the requirements of the MOSFET (e.g. maximum gate-source voltage) and the circuit (e.g. maximum expected drain-source voltage).

MOSFET overvoltage protection by zener diodes
MOSFET overvoltage protection by zener diodes

For example, here I used a 5.1 volt zener diode for switching a 5 volt voltage to reduce the voltage peak between drain and source when the MOSFET opens:

Voltage peak without zener diode
Voltage peak with zener diode

So do you need Z-diodes? Frankly, I don’t know how often MOSFETs actually die because of overvoltage issues. But especially for elaborate projects with inaccessible circuits, you might want to think about it.

Gate driver

As you have seen, the switching speed of a MOSFET is limited when the gate is controlled via the I/O pin of a microcontroller. Likewise there can be problems with high PWM frequencies. In addition, many MOSFETs still have a high RDS(On) value at gate-source voltages of 5 or even 3.3 volts, and thus a correspondingly high power dissipation.

To eliminate these problems, gate drivers (MOSFET drivers) are used. You can build them yourself with a few components, or you can use gate driver ICs.

Gate driver circuits

In the simplest case you build a gate driver from a bipolar NPN transistor and two resistors. With the following circuit I controlled a 12 volt / 0.3 amps electromagnet. As MOSFET again the IRL520 was used, as transistor a BC547B was used. This time I also used a gate series resistor of 100 Ω.

MOSFET control with simple gate driver

It should be noted that the MOSFET switches through as long as the transistor is closed. This means that the magnet is active as long as pin 9 is LOW. If the solenoid is to be switched off, pin 9 goes HIGH. In this state, a base-emitter and a collector-emitter current flows across the transistor. Base and collector resistance should therefore not be selected too small.

The MOSFET gate is controlled with the 5 volts of the Arduino in this circuit. I could have also taken the 12 volt power supply of my load. But then the IRL520 would not have been suitable anymore because its maximum gate-source voltage is 10 volts according to the datasheet.

Despite the 100 ohms series resistor at the gate, the circuit is very fast:

Gate-source (yellow) voltage vs. drain-source voltage (blue), MOSFET circuit with gate driver

You can find more gate driver circuits here.

Gate driver ICs

Alternatively you can buy gate driver ICs as ready-made solutions, like the TC4426A or the IR2117. With the example of the TC4426A I show how to use such ICs.

Pinout TC4426A

With the TC4426A you can control two MOSFETs. It has the following inputs/outputs:

Gate driver TC4426A
  • NC: Not connected
  • IN A / IN B: Logic level input, HIGH: > 2.4 volts
  • GND / VDD: Power supply 4.5 – 18 volts 
  • OUT A / OUT B: Inverted output (0 V / VDD)

Example circuit TC4426A

The circuit is simple:

Example circuit TC4426A
Example circuit TC4426A

Limited suitability: MOSFET “driver modules

If you search for MOSFET drivers on Amazon and similar online stores, you will come across a frequently offered, so-called MOSFET driver module (see below). This designation is misleading, because nothing drives on this module! The signal input is directly connected to the gate of the MOSFET. The pull-down resistor is quite large with 1 kΩ. The MOSFET is an IRF520, so it is not a true logic-level MOSFET. Furthermore, the pin labelling is a bit confusing, since three pins are not used at all. To the credit of the modules, I must say that they work reliably with 5 volts of signal voltage and that they indicate with the LED when a signal is present. In addition, the screw terminals can be quite handy.

MOSFET module
Circuit of the MOSFET module

Which MOSFET should I choose?

I hope the post will make you agree that the answer is it depends! If you want to avoid the use of gate drivers, then first of all already take a logic-level MOSFET. For smaller currents I would go for the smaller TO-92 style MOSFETs like the BS170 or the 2N7000. If large currents are to be handled, the RDS(ON) should be small. In this respect, for example, the IRL3803 is quite good. But these are only a few examples. An excellent overview of MOSFETs can be found here at


The switches on the post image I owe Joseph V M on Pixabay.

2 thoughts on “The MOSFET as Switch

Leave a Reply

Your email address will not be published. Required fields are marked *