Friday, January 3, 2014

Basic LED lighting with a Raspberry Pi Part 1

Hello everyone,

Today I will be speaking about basic LED lighting and circuits with the Raspberry Pi. This article is for those who are looking for a beginner's project to do with their RasPi's and would like to integrate the GPIO capabilities of the Raspberry Pi as well as take advantage of their solderless breadboard! If this sounds like you, please continue to read this tutorial :)

I got my raspberry pi not long ago and had no experience in electronic components, but I did have an interest in learning at least the basics so I could tackle some larger projects as well as learn how to manage the GPIO pins. I learned some things here and there regarding electronic engineering and want to share with my readers the basics on GPIO usage for several reasons. 1) GPIO is a really neat concept and you can have a lot of fun experimenting and making cool gadgets. 2) If you don't know your GPIO pin layout you can easily fry your Pi!!!!!! I CANNOT stress this point enough!!

To begin, I would like to point my readers to a reference of the appropriate pin layout for their raspberry pi. Before I point you to a resource, I would like to explain my reasons. The Raspberry Pi Model B has 2 revisions (up to date). The first revision has a much different pin layout than the second revision. Why does this matter? You could fry your pi if you wire things wrong :-). Frying a Raspberry Pi is not a fun experience! (Unless its  edible). As I mentioned previously, figuring out which revision of Pi you have is very trivial. This website has a clear explanation on how to do it. Once you finish determining your revision, please keep on reading.

If you own a revision 1 Pi, this is the correct pin layout  If you're rocking a revision 2, this is the correct pin layout. Whichever revision of Pi you have, make sure you can always keep the correct pin layout as a reference. Print it out and tape it to your wall if you need to. Make sure you always have it as a reference when you're doing GPIO work. As of now (January 3, 2014), there are only 2 revision of Raspberry Pi Model B's. If you are reading this at a later time and more revisions have been released, just search on Google "Raspberry Pi Revision <REVISION> GPIO Pinout". Check several sources to make sure you've found the correct layout.

If you notice on your pin layouts, you'll see that the columns of numbers skip by 2. For example, here is the pin layout for my Raspberry Pi:

You can see that each column either contains the odd numbers or even numbers. The column containing the yellow box in the upper left hand side has the numbers 1,3,5,7,...,25. And the other column, containing the red box in the upper right hand side has the even numbers 2,4,6,8,...26. This is important to realize! The pin numbering for these GPIO sockets behaves in this manner and you need  to be sure you know which pin  for example, is pin #3, its not 3 from the upper left nor 3 from the upper right. Pin #3 is the pin directly below the yellow box in the upper left hand side that says"3.3V". Why is that pin #3? Well, pin #1 is the yellow box. Pin #2 is the red box in the upper right, so pin #3 must be the box under pin #1.  Its important that you know how to "count pins", so you don't mess up the measurements in the future. Before scrolling down further, I have a quiz for you. Which pin is labeled "GROUND"? Although the pin layout has the numbers and labels right in front of you, the actual raspberry pi won't, so its good practice to start "pin counting". Do you have the answer? There are multiple right answers for this question! For my revision,  Pin #14 is a possible answer, since the black box that is surrounding it has the label GROUND.If you didn't get that, please make sure you understand this before moving on!!

You should be champs at pin counting if you made it this far and answered my quiz question correctly.  Now its time to understand how a breadboard works. This is a very simple concept to understand. There are several tutorials online written for understanding a breadboard, and I encourage you to read any one of the following:   here, here, here, or here (slightly more advanced). However, if this is your reaction to reading a few pages about breadboards:

The concept is very simple. Metal strips run horizontally along the sections where either a current is flowing or there is negative (0 volts). The rest of the board has metal strips running vertically within the columns. I know this explanation was very vague, but combine what I just said with some words of wisdom of those articles I recommended, and you'll be a breadboarding master.

Hopefully by now you understand how a breadboard works, and if you do, you're ready to move on to powering an LED with your raspberry pi!

LED's, like all electronic components, require energy. The LED's I use require 3V and thus can be supplied by the Raspberry Pi without an issue (look at your pin layout, you'll see a 3.3V socket somewhere). Out of this socket, the raspberry pi will "feed" out 3.3V. Here's a picture of the LED's I use:

You can see its just a basic LED, with 2 leads ( one larger than the other). The longer lead is Positive and thus must be connected to the source of energy. The shorter lead is Negative and thus must be plugged to the "negative" of the breadboard, which is GROUND. Note: On some LED's the leads will be the same exact length, so the distinction of Positive and Negative is a little more arbitrary. However, to find out which is which on any LED, the negative side will have a flat surface. This is better seen than described, but unfortunately is kind of difficult to take a picture of but is very noticeable once you're holding an LED.

To build a basic circuit, we're going to need to feed 3V to the positive lead of the LED, but that's not all. We need to "close" the circuit, so it the 3V can be carried throughout the entire circuit. Right now we only have 3V flowing to the LED but the voltage isn't being maintained in a circuit. Enter, GROUND! I mentioned earlier that the shorter lead of the LED was meant for GROUND. And I also quizzed you on which pin is labeled GROUND. This is because GROUND is needed to complete a circuit. You can think of it like this, you would like to know what is the fastest speed that  a tennis ball could strike the ground. As an experiment, you lob the tennis ball in the air and once it hits ground, you perform some calculations, and get the speed. If the ball never were to hit the ground, the experiment would not be complete since it required the ball to touch ground. GROUND on the GPIO level works the same way. You throw the ball with some force (3V in our case), but there's no way to complete the experiment without the ball hitting ground ( connecting the short lead to GROUND in our case). GROUND is analogous to having the tennis ball hitting the ground in this made up experiment. From an electronic point of view, GROUND "unites" the circuit, so energy can flow. From this perspective, you can imagine a large track and field course. Take this track and field course and put some runners( voltage) on it. In a "working" track, the runners will essentially run repeatedly in a circle since the track is enclosed. However, if the track suddenly ended( wasn't connected) and led into an abyss, the runners would never come back! Energy works the same way. GROUND completes the track and allows a flow of energy.

So, I think by now I've stressed the fact about GROUND being so important to a circuit! This being said, in our mind we need to connect 3V to the positive lead of the LED and the negative lead to GROUND. Before we build the circuit, we'll need to understand ribbon cables. This will all be covered in the next part of the tutorial!

I Hope this was informative! Please leave a comment if you have any questions,comments, or concerns. The rest of the circuit will be covered and analyzed in Part 2.

Alejandro Lucena

1 comment:

  1. JackpotCity Casino | Goyang FC
    The excitement 포커 페이스 of Jackpot City is alluring in every city – from its bustling cafes to its thrilling 장원도메인 entertainment, the excitement 호벳 at 슈어 벳 먹튀 their cafes is unmatched