Electrical – What role does a FET play when working with GPIO pins on a Raspberry Pi

fetgpioraspberry pi

I recently asked this question where I'm trying to wire up this momentary switch to my Raspberry Pi 1 Model A such that:

  • The switch is normally open; and
  • When pushed down: it closes the circuit, lights up and fires a HIGH signal to a GPIO input pin (GPIO 04 in my case); and
  • If needed, I can make the GPIO 07 pin an output pin and make it available to help run the light/LED inside the switch, but not sure if that's needed

The answerer to that question provided the following solution:

schematic

simulate this circuit – Schematic created using CircuitLab

I'm just wondering what function this M1 Logic Level FET is performing in the circuit (e.g. why is it there?! why is it needed if I can control signals in/out of the GPIO pins?), as well as confirmation that I could (or can't!!!) use this one to get the job done.

Best Answer

The GPIO pins on the Raspberry PI can only source or sink about 10mA and are damaged when exposed to voltages above 3.3V. The MOSFET effectively acts like a relay (voltage controlled switch) allowing the circuit to control mode than 3.3V and provide mode than 10mA to the load while being driven by a GPIO pin. Note that you can't drive a typical relay from a GPIO pin because the relay coil requires more than 10mA.

Bipolar transistors can also be used to accomplish this function. MOSFETs are often preferred because their effective resistance when on can be much lower than a bipolar transistor (allowing them to handle more current and generate less heat at the same current). MOSFETs also require very little control current (for slow switching speeds) and can switch a very high current from a change in voltage. Bipolar transistors are current amplifiers so there is a ratio (called Beta) between the input current and the output current. This ratio is limited, so it is often necessary to use multiple stages of bipolar transistors to amplify the 10mA drive current into what is required to drive an actual load.

MOSFETs have their own set of challenges. Most N-Channel MOSFETS require the voltage difference between the gate and the source to be 5-8V in order to fully turn on, which is needed to switch high currents efficiently. Logic level MOSFETS are available with lower voltage drive requirements (reduced variety and often increased cost).

EDIT: RPI GPIO current limit appears to be 16mA per pin with a total limit of about 50mA so you need to limit the current to a lot less than 16mA if you are using several GPIO pins.