Wikijunior:Raspberry Pi/Raspberry Pi Python GPIO Zero Simple LED Tutorial

Tutorial by Andrew Oakley Public Domain 24 Sept 2016 www.cotswoldjam.org

Light-emitting diode (LED)
The light-emitting diode (LED) has a short leg and a long leg. If you feel around the rim, you'll also find a flat edge.

The short leg and flat edge always connect to the negative (ground).

Resistor
The resistor can be connected any way around. Any resistor between 220 and 470 Ohms will work fine.

Jumper wires
Jumper wires (also called DuPont wires) connect electronic components to the GPIO pins.

You should also have two short and one long jumper wire (all "female to female" – holes at both ends).

Putting it together
Step 1: Connect one short wire to pin 7 (GPIO 4). This is the 4th pin from the left of the bottom row.

Step 2: Place the resistor at the end of the short wire.

Step 3: Connect another short wire to the resistor.

Step 4: Connect the end of this short wire to the long leg of the LED. This is a positive connection.

Step 5: Next, connect the long jumper wire to the ground (negative). There are several ground pins on the Raspberry Pi, for example, the 5th pin from the left of the bottom row which is pin 9 (GND).

The program
Power up your Raspberry Pi. From the desktop menu, select Programming – Python 3 (IDLE). Then use File, New Window to create a new program.

Type in the following program, or alternatively you can use File, Open to open the  program in the   folder.

Use File, Save to save this program as led.py and then run it by selecting Run menu, Run Module. You should see the LED light up for one second, and then turn off.

Not working? Check that you have:


 * The correct GPIO pins.
 * That the LED is the correct way round; short leg to ground (GND).
 * There are no spelling mistakes, no missing brackets, and you've used round brackets instead of pointy, curly or square ones.

What is this program doing?
The first two lines tell the computer to learn about a new thing. Computers can learn from programs that other people have written, and we call these other programs "libraries". Our instructions tell the computer to learn about LEDs from the GPIOZero library and learn about sleeping from the time library.

We then create an LED object. We say that the LED is connected to GPIO 4.

Turn the LED on, wait for 2 seconds, then turn it off.

See if you can flash SOS in Morse code. Have a look at the  program and learn about the   command.

Cjam-led-gpiozero-tutorial.pdf
The original PDF for this tutorial is available on Wikimedia Commons: