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
All the different sizes and colors
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!