Overview
This tutorial will cover those wonderful blinky things, LEDs. We're going to cover how to calculate the current going through an LED and in the mean time introduce two important laws of electronics, Kirchhoff's Voltage Law and Ohm's Law. We'll begin by performing experiments that will demonstrate how voltage and resistance affects current and then prove those results with a little math.
There's no coding involved in this exercise, and although we use an Arduino in the images, you don't need one to follow along. We do suggest some other kind of power supply so you can try out the experiments, but you can use even batteries in a battery holder!
Page last edited July 18, 2025
Text editor powered by tinymce.
What is an LED?
Who doesn't love LEDs? They are bright and blinky, or soft and elegant. They're festive! They're colorful! They're everywhere and they're a lot of fun. We love LEDs when we write tutorials because most of electronics hackery is hidden in chips, or goes very fast and we can't see or sense it without expensive equipment. But LEDs are easy to see for everyone - this way we can visually identify what is going on inside our microcontroller.
Lets begin with an anatomy lesson…The Parts of an LED!
LEDs are so common, they come in dozens of different shapes and sizes. The LEDs you are most likely to use are the through hole LEDs with two legs. There are lots of LEDs that are small and hard to solder but these are easy to use with a breadboard because they have long wires we can stick in. The clear or clear-ish bulb is what protects the light emitter (thats where the magic happens). In fact, the first two letters of LED stand for Light Emitting.
A really nice thing about LEDs is that they are very simple. Unlike some chips that have dozens of pins with names and special uses, LEDs have only two wires. One wire is the anode (positive) and another is the cathode (negative). The two wires have different names because LEDs only work in one direction and we need to keep track of which pin is which. One goes to the positive voltage and the other goes to the negative voltage. Electronic parts that only work in 'one direction' like this are called Diodes, thats what the last letter of LED stands for.
- The longer lead goes to the more-positive voltage
- Current goes in one direction, from the anode (positive) to the cathode (negative)
- LEDs that are 'backwards' won't work - but they won't break either
It's all a little confusing - we often have to think about which is which. So to make it easy, there's only one thing you need to remember and that's the LED wont light up if you put it in backwards. If you're ever having LED problems where they are not lighting, just flip it around. Its very hard to damage an LED by putting it in backwards so don't be scared if you do
If it helps, refer back to these photos and diagrams or print them out for your reference
5mm LEDs! Green, Red, Blue (in a clear case) and InfraRed (in a bluish case)
One of the best things about modern LEDs is all the colors they come in. It used to be that LEDs were only red or maybe yellow and orange, which is why early electronics from the 70s and 80s only had red LEDs. The color emitted from an LED has to do with what type of material they are made of. So red, for example, is made with Gallium Arsenide. Since then, scientists have experimented with many other materials and figured out how to make other colors such as green and blue, as well as violet and white. (You can see a massive table of all the different materials used to make LEDs in the wikipedia page )
When we first started making electronics in the late 90's, we bought some 5mm blue LEDs and they were $3 each. Now you can get easily a dozen LEDs for that price. Life is good!
Green 3mm, Red 5mm and White 10mm LEDs
- 5mm LEDs can be so bright, they are often used as illumination (lighting something up, like a flashlight, we'll talk about this next).
- 3mm LEDs are not as bright but are smaller, and are good for indication (like an LED that tells you something is on). They're not as good for illumination because they have a smaller area that is lit.
- 10mm LEDs are a little more rare, they are huge and chunky but are usually just 5mm LEDs with a bigger case so they aren't any brighter. They can be good indicators but we rarely see them as illuminators.
Page last edited July 18, 2025
Text editor powered by tinymce.
What are LEDs used for?
Illumination means to "shine light onto something" - like a flashlight or headlights. You want your headlights to be bright as heck.
Brake lights should be bright enough to see, but don't need to light up the road!
Indication mean to "point something out" - like a turn signal or brake lights on a car. You don't want your car's turn signal to blind people!
If you get the wrong type you could end up with a DIY flashlight that is dim, or a control panel that burns people's eyes!
Diffused LEDs are really good at indication, they look soft and uniform and you can see them well from any angle.
Clear LEDs are really good at illumination, the light is direct and powerful - but you can't see them well from an angle because the light is only going forward.
Let's verify this. On this breadboard I've connected two LEDs, one Red Diffused and one Clear Bright Blue LED. Both have the same resistor (which means they're basically using the same amount of power). You should follow along, wiring up one of each. Use a 1.0K or so resistor from the cathode (shorter pin) to Ground and connect the anode (longer pin) to +5V.
Probably not visible in daylight. 200 "Somewhat dim" indicator, about the brightness of the red diffused LED in the example above. Not visible in bright daylight.
You can easily look at these 500 "Kinda bright". About the brightness of the red diffused LED if you powered it up all the way (we'll do that later).
You can look at these if you're more than a few inches away, otherwise you'll see spots. 1,000 "Fairly bright", about the brightness of the clear LED in the previous example, maybe about the brightness of those cheap LED keychain flashlights.
You can look at these if you're more than a few inches away, otherwise you'll see spots. 5,000 "Bright!" - these are as bright as ultra-bright 5mm LEDs get. If you powered the clear LED all the way (we'll do that later). Expensive 5mm LED flashlights, when new, are about this bright.
Looking directly at this is not pleasant. 20,000 "Really Bright" - 5mm LEDs cant get this bright, but if you get the "1 Watt" LEDs, they'll easily give you 20 candela of light. These are good for bicycle headlamps, big bright flashlights, and such.
Don't look straight at these, it'll hurt your eyes.
Changing the brightness with resistors
Lets go back to our basic LED setup: one LED and one resistor connected from 5V to ground. This time we will duplicate it so that we have three LEDs except that each resistor is going to be different. LED #1 will have a 100 ohm resistor (Brown Black Brown), LED #2 will have 1.0K (Brown Black Red) and LED #3 will use a 10K (Brown Black Orange).
With a 5K resistor, it would be brighter than the 10K resistor-LED, but dimmer than the 1K resistor-LED.
Changing the brightness with voltage
Having learned a little about how to use resistors to change the brightness of an LED, we will now try experiment #2. This time we will use only 1.0K resistors but connect the anodes to different voltages. One LED anode will go to 3.3 volts another will go to 5.0 volts and the third will go to Vin (which, if you have one of our starter packs, goes to a 9V wall adapter, so its 9.0 volts
Connected to 4v, it would be brighter than the 3.3v LED and dimmer than 5v.
Max brightness!?
Lets do another quick experiement. Lets say we had a magical resistor with a knob, that we could change the resistance of from 0 resistance (like a piece of wire) to infinite resistance (something that does not conduct, like rubber).As the resistor gets smaller, from infinity to zero, the LED will get brighter and brighter.
As the voltages goes higher and higher, the LED will get brighter.
It would seem, then, that if we want a really really bright LED, we should just use a zero ohm resistor and connect to the highest voltage we can, right? And who wouldn't want an LED thats as bright as possible?
Lets build an LED circuit with a zero ohm resistor (also known as a wire) to Vin so be sure to plug in the Arduino into the wall with a plug-pack/wall-wart. (For somewhat detailed reasons we'll cover in another tutorial, using the 3.3V or 5V power pins won't do what we want, we need to use Vin).
Page last edited July 18, 2025
Text editor powered by tinymce.
The LED datasheet
Now that we know that even the mighty LED has its limits, we need to make sure we stay below those limits. Being kind to your LEDs will let them last longer and keep them shiny & bright!
Lets examine the specification sheet for a 5mm LED, specification sheets are also called datasheets. Datasheets are immensly useful, they have all the information you need for an electronic component. You can download the datasheet we'll be referring to here.
The first useful thing you'll find is the dimensional 'package' information. The 'package' here is the LED itself.
As you can see, the main diameter of the LED is 5mm (its a '5mm LED') and there's a lip that makes it around 6mm. The lip can make it handy if you're gluing the LED into a drilled hole, so it doesnt fall through. The datasheet also tells you which pin is the cathode and other lengths and sizes. Note that the figures are in mm with the inches in ()'s afterwards.
Keep scrolling down. Next you'll find this small table. This section tells you how bright the LED is in mcd. Since these are general purpose LEDs, the brightness can vary a bit, these LEDs average around 250 mcd, but the manufacturer may sell you LEDs that are as dim as 180mcd. This variation is pretty standard.
The first two rows talk about the 'wavelength' - this is a specific way of indicating the color. After all, 'super bright red' is a very subjective description. With the wavelength, we can know exactly what color is emitted.
The third row is basically saying 'how much does the color vary from the wavelength'
The forth row isnt so important, we'll skip that
The fifth row, however, is what we're looking for…
Page last edited July 18, 2025
Text editor powered by tinymce.
Forward Voltage and KVL
In any 'loop' of a circuit, the voltages must balance: the amount generated = the amount used
This "Voltage Loop" law was discovered by a fellow named Kirchhoff (thus it is called Kirchhoff's Voltage Law = KVL). And we can see the loop above, where one part is made of the +9V battery. The other half must use up the +9v (making it -9V so that both halves of the loop equal out).
So what does this have to do with the Forward Voltage of an LED? Well, the Forward Voltage is the 'negative voltage', used by the LED when it's on. Kinda like a 'negative battery'! So lets modify our diagram slightly.
Quick Quiz!
Voltages Generate = Voltages used, so 5V = 2.5V + ResistorVoltage. The voltage across the resistor is 2.5V.
Voltages Generate = Voltages used, so 5V = 3.4V + ResistorVoltage. The voltage across the resistor is 1.6V.
Ohm's Law
What is interesting about the law we just learned (KVL) is that in no place do we use the resistance of the resistor. It never shows up in the equation. Yet from our previous experiements we know for a fact that changing the resistance affects how bright the LED is. There must be something else going on, lets keep working on understanding the details….Next we're going to throw in another important law. This one is called Ohm's Law- and it describes how resistors work.
Voltage across a resistor (volts) = Current through the resistor (amperes)* The Resistance of the resistor (ohms)
There's a more common shorthand notation which you'll see very often:
V = I * R
Or the two other ways of writing to solve for current or resistance:
I = V / R
R = V / I
The V is for voltage, the R is for resistance and the I, confusingly, is for current. Yeah, that I is a little annoying isn't it, since theres not even a single I in the word current? Unfortunately, there are 100 years working against us here, so just bear with us on that one.
Quick Quiz!
We'll use the V = I * R form of Ohm's Law. V = 0.5 A * 3 ohm = 1.5 Volts.
We will use the I = V / R form of Ohm's Law. Current = 6.8 V / 1000 = 6.8 milliAmps.
Solving for the current
We'll now combine both KVL and Ohm's Law with our diagram. Our LED is connected to a 1000 ohm resistor (you should verify this by checking the resistor color stripes!), and the voltage across that resistormust be 6.8V (the law of KVL) so the current through that resistor must be 6.8V / 1000ohm = 6.8 mA (Ohm's law).
The amount of current (I) going through an LED is directly proportional to how bright it appears.
Aha! Finally, the last piece of the puzzle. If we increase the current, the LED will be brighter. Likewise, if you decrease the current, the LED will be dimmer. By picking the correct resistor, you have full control over how the LED appears.
Most of the time, you'll want to have a really bright LED so you'll be calculating the smallest resistor you can get away with and not damage the LED. But note that the more current used by the LED, the quicker you'll drain the battery. So there are good reasons for wanting to control the brightness if say you have a small battery and you want the lights to last a long time.
Since as we have seen, too much current will make the LED go poof, what is the best amount of current we should use? For some very big 'power LEDs', the current can be as high as 1 or 2 Amperes, but for pretty much every 3mm, 5mm or 10mm LED, the amount of current you're expected to use is 20mA. You can see this in the datasheet we talked about earlier. See the right-most column? IF is the Forward Current (I) and they use 20mA.
Page last edited July 18, 2025
Text editor powered by tinymce.
Revisiting Resistors
Quick Quiz!
This is a KVL question. 5V = 2.2V + Vresistor so Vresistor = 2.8V.
We determined the voltage (V) is 2.8V, we use Ohm's Law I = V/R = 2.8/10000 = 0.00028 Amps = 0.28 milliAmps.
You didn't get fooled by this one right? The voltage is exactly the same, the resistance does not matter for KVL, it is still 2.8V.
We determined the voltage (V) is 2.8V, we use Ohm's Law I = V/R = 2.8/1000 = 0.0028 Amps = 2.8 milliAmps.
We determined the voltage (V) is 2.8V, we use Ohm's Law I = V/R = 2.8/100 = 0.028 Amps = 28 milliAmps.
Page last edited July 18, 2025
Text editor powered by tinymce.
Revisiting Volts
Quick Quiz!
This is a KVL question. 9V = 2.2V + Vresistor so Vresistor = 6.8V
We determined the voltage (V) is 6.8V, we use Ohm's Law I = V/R = 6.8/1000 = 0.0068 Amps = 6.8 milliAmps.
Another KVL! 5V = 2.2V + Vresistor. Vresistor = 2.8V
We determined the voltage (V) is 2.8V, we use Ohm's Law I = V/R = 2.8/1000 = 0.0028 Amps = 2.8 milliAmps.
Another KVL! 3.3V = 2.2V + Vresistor. Vresistor = 1.1V
We determined the voltage (V) is 1.1V, we use Ohm's Law I = V/R = 1.1/1000 = 0.0011 Amps = 1.1 milliAmps.
Page last edited July 18, 2025
Text editor powered by tinymce.
Which to Adjust?
The battery (or power supply) generates power, the LED and resistor both use power, but they do so in different ways. The LED uses the power to make light (more power, more light). The resistor does not make light, it makes heat (more power, more heat). And as you know from the last quiz, any voltage left over from the LED is used by the resistor. That voltage & current in the resistor is lost forever as heat and doesn't do anything useful in our circuit. Since it's inefficient to just pump all our battery power into the air as heat, we should make the power used by the resistor as small as possible, and the best way to do that is to keep the voltage low.
The upshot? If you need to make an LED brighter, adding batteries is wasteful: you're better off using a smaller resistor! If you are making up a power supply, by adding up AA's in a pack, try to have about half or one volt minimum 'headroom' above the highest forward voltage, so that you can have a small resistor, around 100 or 200 ohms. Going lower than that isn't suggested because the forward voltage can vary, and resistors can vary, and the battery can vary and all these little variances of 0.2 Volts or so add up and you won't get the brightness you want.
Page last edited July 18, 2025
Text editor powered by tinymce.
Adjusting Brightness
We'll finish up by introducing another part that's in your kit bag. This is the potentiometer (sometimes also called a pot because the word potentiometer is just terribly long)
Recall oh so many hours ago, when we talked about having a magic resistor that we could change from 0 ohms to infinite ohms and used that to think of how resistance changed LED brightness? Well, that isn't such an imaginary thing after all, in fact they are quite common. Potentiometers are resistor that are adjustable with a knob. We will talk about potentiometers more in detail in a future tutorial so consider this a light introduction!
The resistance between the two outer pins is always the same. The resistance between the middle pin and the left or right pin changes!
Quick Quiz!
In the middle, it will be 1/2 of the maximum, 1Kohm
Note that we are connecting to the wiper and one end, not to both ends. Also, we have a 100 ohm resistor between the potentiometer and the LED.
Please try to build this circuit, verify that the LED dims and brightens when the potentiometer is turned.
The 100 ohms gets added to the resistance of the potentiometer!
Quick Quiz!
When 'turned down' the potentiometer resistance between the middle pin and the left pin is zero ohms. 0 + 100 = 100 ohms total.
When the potentiometer is turned all the way up, the resistance is 10Kohms = 10,000 ohms. adding 100 ohms makes it 10,100 ohms.
Last Quick Quiz!
(5 - 2.2V) / 100 ohm = 28 milliamps.
(5V - 2.2V) / 10100 ohm = 0.28 milliamps.
Page last edited July 18, 2025
Text editor powered by tinymce.