A Diode is an electronic component that allows current to flow in only one direction. An LED, or Light Emitting Diodes, is a diode that illuminates when sufficient voltage and current is supplied. They are polarised components meaning they have a right and wrong way of being connected.
The schematic symbol of an LED is shown below.
The horizontal line is the wire. The triangle and vertical line combine to form the standard symbol of a diode. The two arrows indicate this diode is an LED. The triangle and vertical line indicate the flow of the current. The vertical line indicates a "wall" that the current can't flow back through. A is the anode, and is where the current flows in. K is the cathode, where the current flows out. These names come from the days of vacuum tubes.
To illuminate the LED correctly, a voltage and sufficient current must be applied to the diode. The datasheet of an LED will give some important parameters...
|IF||Forward Current||This is the current that runs through the device when it is running. The maximum IF is the continuous current that can run through the device without damaging it, but when run at this value, it does reduce the life of the LED. (LEDs dim after time). Don't confuse this with IFP, the peak forward current which can only be applied for a short pulse, typically 0.1ms.|
|VF||Forward Voltage||This is amount of voltage that drops across the LED. For
linear devices, like resistors, Ohms law states V=IR, where V is the
voltage, I is the current, and R is the resistance. As the current
through a resistor increases, the voltage across the resistor increases.
LEDs, on the other hand, have a pretty constant voltage drop. As the current changes, VF stays about the same. The LED datasheet will specify the VF values for a given IF value. Use these values in calculating the current limiting resistor (see below).
Current Limiting Resistor
If an LED was connected directly to a voltage source, we would end up with the following schematic of the circuit.
In this circuit, we ignore the resistor (the squiggly line), that is, it's resistance is zero. We can use Ohms V=IR, law to make an equation representing the circuit...
Vtotal = VF + R.I
[The total voltage is the sum of the voltage drops. Also, the current is the same through each component]
We know the total voltage, Vtotal=5 volts. We know the voltage drop across the LED, VF=2 volts (from the data sheet), and we know the resistance of our resistor in the circuit R=0 Ohms. Therefore,
5 = 2 + 0.I
|I =||5 - 2|
The two divided by zero, gives the current, I, as infinite, or at least very large, because there are small resistances in the wires and the power source. What this example is trying to show is that you can't just connect an LED to a power source without some way of controlling the current flow.
By using the first equation, and the Forward Voltage and Forward Current from the LED datasheets, we can calculate the value of resistor we need to limit the current in the circuit.
|R =||Vtotal - VF|
If VF=2, and IF=20mA, or 0.020A, we have...
|R =||5 - 2||= 150 Ohms|
A 150 Ohm resistor will give a 20mA current. Note that for most LEDs, 20mA is incredibly bright. For panel indicators, a small IF of 5mA or less will usually suffice. Also, electronics isn't terribly fussy with parameter value selection. If you don't have a 150 ohm resistor handy, the next higher value should be fine.
According to the Atmel datasheets, the maximum current supplied or sunk by any individual pin is 40mA. The total current drawn from port combinations must not be exceeded. These limits are shown in the following table.
|Port Group||Maximum Current|
|PA0..PA7 + PG2 + PC4..PC7||100 mA|
|PC0..PC3 + PG0..PG1 + PD0..PD7||100 mA|
|PG3..PG5 + PB0..PB7 + PE0..PE7||100 mA|
The total current limit for the microcontroller is 200mA.
However, to ensure a long life, it is recommended that there values are never approached. LEDs can normally be illuminated on very small currents, usually in 1-2mA range. A simple test circuit, or a cheap LED tester will help select a suitable current. Remember, these LEDs are only going to be used as indicators, not room lighting.