Computers, Laptops & Tablets Accessories & Hardware 20 20 people found this article helpful How to Light an LED with the Raspberry Pi's GPIO By Richard Saville Writer Richard Saville is a former Lifewire writer and computer enthusiast who has invented several add-on boards for Raspberry Pi and has been published in MagPi and other outlets. our editorial process Facebook Twitter Richard Saville Updated May 19, 2019 Choosing your first Raspberry Pi can be confusing for new enthusiasts. Richard Saville Accessories & Hardware Raspberry Pi Keyboards & Mice Monitors Cards HDD & SSD Printers & Scanners Tweet Share Email The GPIO is how the Raspberry Pi talks to the outside world. It uses code to program the signals and voltages to and from the 40-pin header. Coding with the GPIO is reasonably simple to get started with, especially for beginner projects such as LEDs and buzzers. With just a couple of components and a few lines of code, you can light or flash an LED as part of your project. This tutorial shows what you need to light an LED using Python code on your Raspberry Pi by using the traditional 'RPi.GPIO' method. 01 of 04 What You Need to Start the Project Richard Saville To start the project, you'll need to begin with the list of items below. You should be able to find these items in your favorite maker store or online auction sites. A Raspberry Pi workstation running the latest Raspbian (Pi, screen, keyboard, mouse, power, SD card)A small breadboardA 5mm LEDA 330-ohm resistor2 male to female jumper wires 02 of 04 Step 1 - Create the Circuit Richard Saville We're going to use 2 GPIO pins for this project, a ground pin (physical pin 39) for the ground leg of the LED, and a generic GPIO pin (GPIO 21, physical pin 40) to power the LED - but only when we decide to - which is where the code comes in. Firstly, turn off your Raspberry Pi. Now, using the jumper wires, connect the ground pin to a lane on your breadboard. Next do the same for the GPIO pin, connecting to a different lane. 03 of 04 Step 2 - Create the Circuit Richard Saville Next, add the LED and resistor to the circuit. LEDs have polarity, which means they have to be wired in a certain way. They usually have one longer leg, which is the anode (positive) leg, and usually a flat edge on the LED plastic head, which denotes the cathode (negative) leg. A resistor is used to protect both the LED from receiving too much current, and the GPIO pin from giving too much. This could damage both. There is a bit of a generic resistor rating for standard LEDs: 330ohm. There is some math behind that, but for now, focus on the project and you can always look into ohms law and related topics afterwards. Connect one leg of the resistor to the GND lane on your breadboard, and the other resistor leg to the lane connected to the shorter leg of your LED. The longer leg of the LED now needs to join the lane connected to the GPIO pin. 04 of 04 Step 3 - Python GPIO Code (RPi.GPIO) Richard Saville At this moment, you have a circuit wired up and ready to go, but now you haven't told the GPIO pin to send out any power yet. So, your LED shouldn't be lit. The next step is to make a Python file to tell the GPIO pin to send out some power for 5 seconds and then stop. The latest version of Raspbian will have the necessary GPIO libraries installed already. Open a terminal window and create a new Python script by entering the following command: This will open a blank file for us to enter our code. Enter the lines below: Press Ctrl+X to save the file. To run the file, enter the following command in the terminal and press enter: The LED should light for 5 seconds then turn off, ending the program.