0
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ It keeps the 6V from destroying the device. \$\endgroup\$ – Ignacio Vazquez-Abrams Oct 9 '17 at 17:45
  • \$\begingroup\$ Thanks @IgnacioVazquez-Abrams (+1) but just curious...if the device is rated at 6VDC, then why do we need a FET to stop 6V from destroying it? \$\endgroup\$ – smeeb Oct 9 '17 at 18:06
  • 1
    \$\begingroup\$ "The device" is the RPi, not the load. \$\endgroup\$ – Ignacio Vazquez-Abrams Oct 9 '17 at 18:07
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the amazing answer @Dean Franks (+1) - I'm following almost everything you say. How about the FET on DigiKey that I provided a link for up above...would that work for my application? If not, any chance you can nudge me in the right direction (DigiKey or Mouser alike)? Thanks again! \$\endgroup\$ – smeeb Oct 9 '17 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.