RPi GPIO Interface Circuits
This page shows a number of common circuits used for interfacing the Raspberry Pi's GPIO pins to various other electronic circuits.
Please note: this page is currently under construction
This circuit may be used to connect a digital signal from a 5V device to a GPIO pin on the Pi, which requires a 3.3V input level. The Ov point in the schematic should be connected to one of the Ground lines on the Pi's GPIO connector, and also to the 0v (or Ground) signal on the input device.
The important thing here is the ratio of R1 to R2; R1 should be just over half R2's value to ensure 5V is divided down to 3.3V. The values shown here should be suitable for most uses.
(See the [http://en.wikipedia.org/wiki/Voltage_divider Wikipedia article on voltage dividers).
The GPIO pins are connected directly to the BCM2835 chip at the heart of the Raspberry Pi. These provide only a 3.3V output level, and are not capable of supplying much power. More importantly, if they are damaged through misuse the Pi itself will need to be replaced.
So, if you are connecting anything more than a small LED to the GPIO output, you should use an additional circuit to boost the voltage and/or current.
Using an NPN transistor
This shows a cheap NPN transistor being used to switch a load on and off. When the GPIO is 'high' (logic 1) the load will be turned on; when it is 'low' the load will be off. The circuit shows a 5V power rail, but with the 2N3904 transistor shown, a supply of up to 40V may be used (this is the VCEO value given in the transistor's datasheet). It should be suitable for a load current of up to 100mA.
For bigger loads, you will need a bigger transistor to switch higher voltages (the VCEO value) or currents (the IC value), but note that you will need a transistor with a higher gain (the hFE value) as well. The gain is the ratio of the current in R1 (in this case, about 2.5mA), to the current in the load: a 1A load will need a gain of 400. So-called Darlington transistors, such as the TIP112 (1A, 100V) provide high gain at high currents.
Using a FET
A field-effect transistor is another alternative to the ('bipolar') transistor shown above. Again, when the GPIO is 'high' (or 1), the load will be switched on, and 'low' or 0 switches the load off. Resistor R1 is provided for safety; it ensures that the load is switched off if the GPIO is set to be an input.
As with the bipolar transistor circuit, supply voltages higher than 5V may be used for the load. The 2N7000 device has a maximum (VDS) voltage of 60V; it is suitable for load currents of about 100mA.
For bigger loads, you can choose a bigger FET: the current rating (ID) and voltage rating (VDS) are given in the data sheet. Unlike bipolar transistors, FETs do not have a 'gain' to worry about. Instead you should look for a 'threshold' voltage (the input voltage at which the FET begins to turn on) of 3V or less, so that it is properly 'on' when driven from the GPIO's 3.3 volts. Some datasheets don't give a threshold voltage - instead they give a value RDS(on) measured at 2.5 or 2.7 volts. If the FET isn't suitable for 3.3V logic input, this value won't be given. Fairchild's FQP30N06L has a low threshold voltage (2.5V max) and can switch 32 amps at 60 volts.
Note: If you wish to produce new or modified schematics matching the ones above, you can use Inkscape using symbols from File:Circuit_Symbols.svg.