PROJECT - USE MOSFET TO DRIVE AN LED
Objective: demonstrate use of MOSFET
You will need: Raspberry Pi, IRLZ44N MOSFET, LED, 10kΩ and 330Ω resistors, patch leads and small breadboard.
This project demonstrates a simple use of a MOSFET to drive an LED. The Raspberry Pi can drive LEDs without needing to use a MOSFET but where the load on a single pin is more than 16mA or the combined load on all pins is more than 200mA a MOSFET or transistor is needed. You'll also need a MOSFET if you wish to drive a 5V mechanical relay as the current required is about 100mA and more than a single pin can provide.
To use a MOSFET successfully with microcontroller output voltages, you need a logic level MOSFET; these are usually identifiable by an L in the part number, e.g. IRLZ44N or IRL540.
Logic level MOSFETs, such as the IRLZ44N, can be used with Raspberry Pi projects to switch high currents at voltages higher than 5V. The International Rectifier device will switch 47A at up to 55V, subject to being fitted to a suitable heat-sink and de-rated for its expected operational temperature. Not all IRLZ44Ns have the same specification with regards to current limits so check the corresponding datasheet for details of your device. For the TO-220 package the pins are, from left to right in the diagram above, Gate, Drain, Source.
You will need to connect a 10kΩ pull-down resistor across the gate and source connections, otherwise even small electrostatic voltages on the gate will switch on the MOSFET - just touching the bare wire on the gate is sufficient.
The Gate Threshold Voltage, listed in the electrical characteristics as VGS(th), needs to be exceeded for the device to conduct - for the IRLZ44N it's 2V. However, at 2V the MOSFET is barely on and will only conduct a very small current, perhaps 1µA. You need to refer to the charts in the data sheet to see what current you can switch with what gate voltage. In general, the gate voltage will dictate the current you can switch so for circuits based on 3.3V, you may need to use a logic level converter to boost the gate voltage to 5V if your MOSFET does not switch the current you need.
Link to source code. You will need to use the following commands to compile and run the program. You will be using the wiringPi library so it needs to be included on the command line:
gcc rp-blink-mosfet.c -o rp-blink-mosfet -lwiringPi