Gpio and The Raspberry Pi: 3. 1.: Can't
Gpio and The Raspberry Pi: 3. 1.: Can't
Light up an Led
So you want to make an LED light up, You cant just connect an LED and You require the following parts, leads (male to female ends), LEDs, Resistors suitable for
using your Raspberry Pi and Python? light it up it may blow up the light or the LED, Solder-less Breadboard, (The clever little breadboard allows you to create a circuit
even blow up your Pi. All normal without having to solder any components. It is important to make sure you know which way
First things first, GPIO stands for the connections run, usually horizontally), and your Raspberry Pi. It is also worth getting the
electrical safety procedures should be
General Purpose Input Output, LED most up to date Disk Image for you Pi from the official site.
followed. If unsure, dont do it!
stands for Light Emitting Diode. A diode
allows a current to flow, usually in one To calculate what resistor to use with which LED use this tool,
direction. Current is a flow of electrons http://www.hebeiltd.com.cn/?p=zz.led.resistor.calculator
or more commonly known as electricity!
To calculate the resistance value use this useful online tool:
6. PROGRAMMING CODE http://www.csgnetwork.com/resistcolcalc.html
Using Python 2.6 create the program below.
Or, most electronics shops will calculate the LED and resistance to use before you buy.
Import RPi.GPIO as GPIO
GPIO setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT) 4. CONNECTING THE WIRES
GPIO.output(11.True) The first part is to connect the wires, the first from PIN11, this is the output wire which you
will program to provide a current to the LED. The second wire, PIN6 is for the current to
-GPIO.setup(11, GPIO.OUT) tells the Pi which PIN the current is following out of, return back to the Pi and complete the circuit. (This PIN is rated 0V). If you imagine that
-GPIO.output(11.True) tells the Pi that the output is true, therefore the LED is on PINs11 and 6 are taps and are joined together with a pipe. If you turned the PIN 11 tap on
-To turn the LED off use False, GPIO.output(11.False) the water would flow from PIN11 through the pipe to 6. This happens with the current, it
-Use the import Time, and time.sleep(4) between the True and False, flows from PIN 11 through the LED to PIN 6.
(On and Off) to make the LED turn on for 4 seconds then turn off.
You may be required to install the GPIO module. Open the LX Terminal and type 5. CONNECT THE LED
PIN 6
AND THE RESISTOR.
the code, sudo apt-get install python-rpi.gpio
The long leg of the LED is
the positive end which PIN 11
7. RUN THE CODE COMMON ISSUES must be connected to the
Broken LED, wires PIN 11 wire, the current. If
The program will only run in the Super User mode open in wrong PIN,
the LX Terminal and run using the SUDO command.
you get this around the
coding error,
Sudo python the nameofyourprogram.py components not
wrong way you can blow
pushed into the LED. PIN 6 feeds the
breadboard, current back to the Pi.
Resistor too high, PIN6 should be in line with
broken wire the LED short leg. @Dan_Aldred
EXTRA IDEAS: Connect two LEDs: Create a Quiz, if correct answer green LED lights up, if not Red LED lights: Set up a traffic light simulator: If you receive a Tweet the LED lights up