- Published: Tuesday, 10 March 2009
- Written by Digital DIY
- Hits: 10738
LED's are great as indicators, and are very easy to interface with. PIC's can source/sink up to 25mA for each output pin, this is much more than most logic outputs will deliver, and when it comes to driving LED's, well its a simple task for a PIC.
Here's a simple program that will turn an LED on and off every 1 second:
The wiring diagram;
Your LED will have a predefined forward voltage and current, which can be found from the supplier your buy it from. You need to use this forward voltage to calculate the series resistor required. Say for example, my LED had a Vf of 2.0 volts, and and If of 20mA(forward current) . This means that the series resistor needs to drop 3V and yet allow 20mA to pass through it. Simple maths allows us to calculate exactly what resistance we need.
Ohms Law: V = IR
Therefore R = V/I
And if R = 3/0.020
Then R = 150 ohms
Now you know that the series resistor must be 150 ohms or greater to safely run your LED.