Raspberry Pi computers are easy to use with all kinds of hardware and software thanks to how easily customizable the devices are.
One of the best parts about Raspberry Pi computers is the GPIO ports, which can be used to connect your Raspberry Pi to all kinds of hardware via the use of wired connections.
Raspberry Pi motherboards all provide access to these ports and allow users to hook up a massive number of extra devices. Once the hardware is hooked up to the motherboard, it is also possible to program the motherboard to activate these devices.
Today we will take you through exactly how to control LEDs using the GPIO pins of your Raspberry Pi computer. Let’s get into it!
How Do You Hook Up An LED To A Raspberry Pi?
In order to hook up an LED to a Raspberry Pi computer, you will need to make sure that you have access to a Raspberry Pi computer that has been updated to the latest Raspbian OS. You can easily update your Raspberry Pi by heading to the command terminal and entering the command:
“sudo apt-get update
sudo apt-get upgrade”
Once you have entered that command, simply restart the Raspberry Pi, and it will now be running on the latest Raspbian OS.
You will also want to make sure that you have access to a Breadboard, which is a type of circuit board that can be directly connected to a Raspberry Pi motherboard and allows you to hook up wires and devices such as LEDs without needing to solder anything in.
This is useful when experimenting with powering LEDs, as you will not need to commit to any changes to your motherboard.
We also recommend getting a 330-ohm resistor, which can help to ensure that the circuit board is never overloaded and damaged.
This is crucial, as the Raspberry Pi can only supply so much power, but the LED will not know how much power is too much power, so the resistor is needed to keep the Raspberry Pi from being overloaded.
To connect everything together, you are also going to need some jumper wires!
Step 1 – Start Putting Things Together
Grab all of the components that you have gathered, and place them in close proximity so that they are all close to hand.
Place your Raspberry Pi on a flat surface, and ensure that it is not currently connected to power, in order to protect your safety.
Place the Breadboard next to the Raspberry Pi motherboard, running parallel to one another.
Step 2 – Connect Your Ground Pin
Grab one of your jumper wires, and connect it directly to the ground pin on the Raspberry Pi motherboard. Take the other end of the wire, and then connect it to the rail on the Breadboard, which will be denoted by a blue line.
This wire will create a zero-volt grounding circuit which will connect to the cathode, the negative end of the LED.
Step 3 – Connect Your Resistor
Now, grab your resistor, and place one end of the resistor into the slot next to where you plugged the first wire into the Breadboard, before then connecting the other end of the resistor to the column on the Breadboard above where you will connect the positive end of the LED.
Step 4 – Connect Your LED To The Breadboard
This step is very simple. Simply grab the LED, and place it into the Breadboard, with each of its two legs in the right position.
The left foot should be the longest foot, which is the one with the slight kink in its shape at the top. Place this leg into the same column as the end of the resistor, around two pins above.
The other leg, the shorter one, needs to be placed into the pin on the column directly next to the longer leg. This will allow the circuit of power to safely run through the LED.
Step 5 – Connect To Pin 18
Now that you have connected the LED and the grounding wire, simply take one more wire, and connect one end of it to the lowest pin on the column where the right leg of the LED is situated.
Take the other end of the wire, and connect it to pin 18 on the Raspberry Pi motherboard. This will help to provide the necessary power from the motherboard to the connected LED.
Step 6 – Implement The Right Code
Open up the terminal on your Raspberry Pi computer, and type in the code:
“import RPi.GPIO as GPIO
print “LED on”
print “LED off”
From here all you then need to do is run the code. This can be done by typing in:
“sudo python LED.py”
Once you hit enter, you should see the LED light up, assuming you have connected everything properly.
Frequently Asked Questions:
Can Raspberry Pi GPIO Drive LED?
Yes. Though the Raspberry Pi cannot output an incredible amount of power, it is able to provide enough power for around 1 to 2 LEDs.
Can You Control The Led On The Raspberry Pi?
Yes. Provided you make use of the right code on the Raspberry Pi, you can very easily control all kinds of things, such as brightness, or the rate at which an LED flashes.
Does Gpio Provide Power?
Most GPIO sets are able to provide around 3.3 volts of power at most. Anything more and the circuit board runs the risk of overloading.
To Wrap Up
As you can now see, operating LEDs can easily be done by making use of a Raspberry Pi, a Breadboard, and the correct code! We hope that this guide has proven, literally, illuminating and that you now feel ready to connect a Breadboard to your Raspberry Pi computer!