
In a P-channel MOSFET, the source is connected to a positive voltage, and the FET will turn on when the voltage on the gate is below the source voltage by a certain amount (Vgs < 0). They are also easier to manufacture, and thus are available for lower prices with higher performance than p-channel MOSFETs.

N-channel MOSFETs are easier to work with, and are the most commonly used type. In an N-channel MOSFET, the source is connected to ground, the drain to the load, and the FET will turn on when a positive voltage is applied to the gate.

This is not to be confused with the diode sometimes placed between the drain and the power supply for the load - this is separate, and should be included when driving an inductive load.Įxcept where noted, this section assumes use of an N-channel enhancement mode MOSFET. This diode, the "body diode" is a consequence of the manufacturing process. MOSFETs only switch current flowing in one direction they have a diode between source and drain in the other direction (in other words, if the drain (on an N-channel device) falls below the voltage on the source, current will flow from the source to the drain). As demonstration, one can wire up a MOSFET normally, except connecting nothing to the gate pin, and then touch the gate while holding either ground or a positive voltage - even through your body’s resistance, you can turn the FET on and off! To ensure that a MOSFET remains off even if the pin is not connected (ex, after Espruino is reset), a pull-down resistor can be placed between gate and source. The voltage on the gate determines whether current can flow from the drain to the load - no current flows to or from the gate (unlike a bipolar junction transistor) - this means that if the gate is allowed to float, the FET may turn on, or off, in response to ambient electrical fields, or very tiny currents. The source is connected to ground (or the positive voltage, in a p-channel MOSFET), the drain is connected to the load, and the gate is connected to a GPIO pin on the Espruino. MOSFETs have three pins, Source, Drain, and Gate. MOSFETs can only be used to switch DC loads. In their off state, MOSFETs are non-conducting, while in their on state, they have an extremely low resistance - often measured in milliohms.

These are useful for controlling loads that draw more current, or require higher voltage, than a GPIO pin can supply. A MOSFET (Metal Oxide-Semiconductor Field Effect Transistor) is a semiconductor device that can be used as a solid state switch.
