What You Can Do with Switched Output on Your Raspberry Pi?

By Sean McManus, Mike Cook

So what can you do with a switched output on the Raspberry Pi? Well, you can drive a small current through a load, or you can control another device that can control a bigger current through a load. Put like that, it doesn’t sound exciting, but it’s what physical computing is all about.

The load can be a light, a motor, a solenoid (an electromagnetic plunger used to prod or strike things), or anything that uses electricity. As that includes most everything in the modern world, it is safe to say that if it uses electricity, it can be controlled.

Take a look at controlling a light, known as a light-emitting diode (LED). These can light up from just a tiny bit of current and the 16mA you have available is more than enough. In fact, you’re going to limit the current to less than 10mA by adding a 330R series resistor.


This shows two ways to wire up an LED, or any other load, directly to a GPIO pin. Here you can see the GPIO pin and not the equivalent series resistance of the power source — in the context of a 330R resistor, 31R is negligible.

The first way to wire it is called current sourcing and is perhaps the way a beginner might think of as natural. When the GPIO pin is set by the program to produce a high voltage, current flows from the pin through the LED, through the resistor and to ground, thus completing the circuit, causing current to flow and so lighting up the LED.

When the GPIO pin is set by the program to produce a low voltage (that is, set the switch to connect the 0V or ground line to the output pin), no current flows and the LED is not lit. This method is known as current sourcing because the source of the current, the positive connection of the power, is the GPIO pin.

The second way of wiring is known as current sinking. When the GPIO pin is set by the program to produce a low voltage, the current flows through the LED, through the resistor, and to ground, through the GPIO pin. To turn the LED off, set the output to a high voltage.

There’s no way current can flow round the circuit because both ends of the load (LED and resistor) are connected to 3V3, so there is no voltage difference to push the current through the components.

Note in both circuits the position of the resistor and LED can be interchanged — it makes no difference. You might like to think of these two approaches as switching the plus and switching the ground.