Post by Honus on Sept 18, 2014 5:53:03 GMT
I get lots of questions about LEDs so I thought I'd give a basic primer on their use.
LEDs (light emitting diodes) come in a lot of different packages (through hole and surface mount) but all LEDs have a positive lead (called the anode) and a negative lead (called the cathode.) Like all other diodes, electrical current only flows through them in one direction- from the anode to the cathode. Because of this LEDs won't light up if they are installed backwards. You won't hurt a LED if you install it backwards- it just won't light up.
The most important thing when using LEDs is to be sure to use a resistor- this limits the amount of current that flows through the LED. When you increase the current the LED gets brighter and when you decrease the current the LED gets dimmer. With the exception of specialty high power LEDs most LEDs you will use in a project will have an optimal current draw of 20mA. This is what is known as the Forward Current and you will see this number on LED datasheets along with the Forward Voltage. You can bump up the Forward Current to make LEDs a bit brighter (maybe 30mA) but if you up the current too much you'll burn out the LED. You can also adjust the brightness by altering the Forward Voltage. Ideally you want to use the lowest voltage necessary and then adjust the current draw by altering the resistance value.
The easiest way to figure out what the proper resistor value is to use an online LED calculator.
This simple tool allows you to enter in your supply voltage, LED voltage drop (Forward Voltage), LED current rating (Forward current) as well as the number of LEDs you want to use. The calculator will then tell you the proper resistor value to use and also give you a wiring diagram. If you want to calculate it yourself you need to read up on Ohm's Law. Ohm's Law is one of the fundamental building blocks of learning about electronics and is well worth investigating. Now back to LEDs...
As an example, let's say we want to make a chest light for an Iron Man costume and we want to use 24 white LEDs. If we're using four AA alkaline batteries our pack voltage will be 6.0V. I used 6.0V because this is a commonly used voltage for powering servos so you can power a bunch of LEDs and servos from the same battery pack. A standard super bright white 5mm LED will have a max voltage drop of around 3.4V and a current rating of 20mA. Plugging those numbers into the calculator we get a resistor value of 130 Ohms and a total current draw of 480mA.
This is what the wiring diagram looks like-

So there you have it! But now how do you connect this to an Arduino to turn all those LEDs on and off? You can't power all those LEDs directly from an Arduino output pin- the Arduino can't deliver anywhere near enough current. What you need is a transistor. A transistor will allow you to power all those LEDs directly from a battery pack and turn them on and off with the Arduino.
The easiest way to describe a transistor (at least for our purposes) is to think of it as an electronic switch. When the transistor is connected to an Arduino output pin and the pin is set to go HIGH the transistor allows current to flow to ground. When the output pin is LOW it blocks the flow of current to ground. There are many types of transistors and they all behave differently. A very common one to use in the instance of our LED circuit is called a Darlington transistor- specifically a TIP120. This type of transistor can easily handle the power requirements of our LED circuit. The transistor has three pins- the base, collector and emitter.

The base is connected to the output pin of the Arduino with a 1K Ohm resistor (this protects the Arduino output pin.) The emitter is connected to ground. The collector is connected to the ground side of the LEDs.
Here's the wiring diagram. As you can see it's super simple. Now you can easily turn a whole bunch of LEDs on and off from a single output pin. If you connect the transistor to a PWM pin you can also fade the LEDs.
Next up I'll talk a bit about high power LEDs...
LEDs (light emitting diodes) come in a lot of different packages (through hole and surface mount) but all LEDs have a positive lead (called the anode) and a negative lead (called the cathode.) Like all other diodes, electrical current only flows through them in one direction- from the anode to the cathode. Because of this LEDs won't light up if they are installed backwards. You won't hurt a LED if you install it backwards- it just won't light up.
The most important thing when using LEDs is to be sure to use a resistor- this limits the amount of current that flows through the LED. When you increase the current the LED gets brighter and when you decrease the current the LED gets dimmer. With the exception of specialty high power LEDs most LEDs you will use in a project will have an optimal current draw of 20mA. This is what is known as the Forward Current and you will see this number on LED datasheets along with the Forward Voltage. You can bump up the Forward Current to make LEDs a bit brighter (maybe 30mA) but if you up the current too much you'll burn out the LED. You can also adjust the brightness by altering the Forward Voltage. Ideally you want to use the lowest voltage necessary and then adjust the current draw by altering the resistance value.
The easiest way to figure out what the proper resistor value is to use an online LED calculator.
This simple tool allows you to enter in your supply voltage, LED voltage drop (Forward Voltage), LED current rating (Forward current) as well as the number of LEDs you want to use. The calculator will then tell you the proper resistor value to use and also give you a wiring diagram. If you want to calculate it yourself you need to read up on Ohm's Law. Ohm's Law is one of the fundamental building blocks of learning about electronics and is well worth investigating. Now back to LEDs...
As an example, let's say we want to make a chest light for an Iron Man costume and we want to use 24 white LEDs. If we're using four AA alkaline batteries our pack voltage will be 6.0V. I used 6.0V because this is a commonly used voltage for powering servos so you can power a bunch of LEDs and servos from the same battery pack. A standard super bright white 5mm LED will have a max voltage drop of around 3.4V and a current rating of 20mA. Plugging those numbers into the calculator we get a resistor value of 130 Ohms and a total current draw of 480mA.
This is what the wiring diagram looks like-

So there you have it! But now how do you connect this to an Arduino to turn all those LEDs on and off? You can't power all those LEDs directly from an Arduino output pin- the Arduino can't deliver anywhere near enough current. What you need is a transistor. A transistor will allow you to power all those LEDs directly from a battery pack and turn them on and off with the Arduino.
The easiest way to describe a transistor (at least for our purposes) is to think of it as an electronic switch. When the transistor is connected to an Arduino output pin and the pin is set to go HIGH the transistor allows current to flow to ground. When the output pin is LOW it blocks the flow of current to ground. There are many types of transistors and they all behave differently. A very common one to use in the instance of our LED circuit is called a Darlington transistor- specifically a TIP120. This type of transistor can easily handle the power requirements of our LED circuit. The transistor has three pins- the base, collector and emitter.

The base is connected to the output pin of the Arduino with a 1K Ohm resistor (this protects the Arduino output pin.) The emitter is connected to ground. The collector is connected to the ground side of the LEDs.
Here's the wiring diagram. As you can see it's super simple. Now you can easily turn a whole bunch of LEDs on and off from a single output pin. If you connect the transistor to a PWM pin you can also fade the LEDs.

Next up I'll talk a bit about high power LEDs...