Getting Started with the Pi's GPIO Port
The Raspberry Pi's General Purpose Input/Output port is the 26 pin connector labelled P1 at the top left of the board. We use a GPIO breakout board, which enables easy attachment of wires to labelled paddle terminals. Our rainbow ribbon cable connecting P1 to the breakout board is not colour coded in the conventional way (with the end brown wire connected to pin 1). Presumably this is because of the unconventional orientation of P1 on the Pi. GPIO Electrical Specifications provides this warning: "Note that the orientation of P1 differs from the convention used in most connector placement. On most computer boards the header would be rotated 180°, so that the odd-numbered row would lie alongside the board edge, instead of the even-numbered row. That way, the wires or ribbon cables running from the edge of the board are numbered from left to right. The Raspberry Pi board violates the convention, placing its even-numbered rows along the board's edge. So be careful in making your connections."
- Type Ctrl+F9 to build the project without running the executable gpio_input.
- Change the current directory to that of gpio_input using the cd command.
- Type at the command prompt sudo ./gpio_input.
In the simple circuits described below there is a wide range of component properties that will work. For example, you could use a 200 ohm (instead of 1 kilohm) resistor for output to an LED and a 2.2 (instead of 7.5) kilohm resistor to connect to the base of the transistor in the motor circuit.
Output to LED
We used a 3mm 2mA LED in series with a 1 kilohm resistor. Make the connections as follows.
- Connect P1-11 (GPIO17) to one end of the resistor.
- Connect the other end of the resistor to the positive terminal (longer wire) of the LED.
- Connect the negative terminal of the LED to P1-6 (GRD).
See the code for control by a toggle button on a form and by cycling an on-off sequence.
Output to DC Motor
You can use in this circuit a cheap 5V DC motor, a transistor such as Fairchild's BC33825TA or equivalent, a diode such as 1N4001 and a 7K5 (7.5 kilohm) resistor. Use the instructions and/or circuit diagram below when making the connections.
- Connect P1-11 (GPIO17) to one end of the resistor.
- Connect the other end of the resistor to the base (middle wire) of the transistor.
- Connect P1-02 (+5v) to one terminal of the DC motor.
- Connect the other terminal of the motor to the collector of the transistor. See the transistor's data sheet to find out which terminal is the collector.
- Connect P1-06 (ground) to the emitter of the transistor.
- Connect a diode in parallel with the motor for the protection of the transistor. (See an equivalent Arduino example with an explanation). The cathode of the diode (marked with a band on the 1N4001 diode) must be connected to P1-02. Connection the other way round would cause a damaging short-circuit.

Circuit diagram for output to a DC motor
See the code for control by a toggle button on a form and by cycling an on-off sequence.
A stepper or servo motor should be used for precise control. This requires more complex programming, which we intend to cover in a tutorial.
Input from Switch
- ConnectP1-12 (GPIO18) to one terminal of a 7.5 kilohm resistor.
- Connect the other end of the resistor to one terminal of a simple push switch.
- Connect the other terminal of the switch to P1-6 (ground).
Follow these links to the demonstrations.