Logic and LEDS

Discussion in 'The Projects Forum' started by mattieg, Nov 28, 2008.

  1. mattieg

    Thread Starter New Member

    Nov 28, 2008
    8
    0
    Hi

    Im sure this is simple but having a mind blank, hopefully someone here can help.

    I want to have an LED light up when a logic high is transmitted from a pic output pin and turn it off when low.

    I'm sure i need to use a transistor and some curent limitng resistors but being stupid with the layout and maths.

    Any help would be great

    Cheers
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    PIC output pins can source or sink up to 25mA when running at 5v (with the exception of the MCLR pin; it cannot source current.)

    Your LED is rated for max forward voltage (Vf) @ current, and typical Vf @ current.

    Let's say you have a red LED with typical Vf of 2.1v @ 20mA (always calculate using the typical Vf @ current when possible)

    You need to calculate the value of the current limiting resistor (Rlimit) for the LED.

    Rlimit >= (Vsupply - Vf(LED)) / DesiredLEDCurrent
    Rlimit >= (5v - 2.1v) / 20mA
    Rlimit >= 2.9/0.02
    Rlimit >= 145 Ohms
    The closest standard resistor value is 150 Ohms.
    Chart: http://www.logwell.com/tech/components/resistor_values.html
    Let's see what the slight increase in resistance does to the LED current:
    I = E/R (Current = Voltage / Resistance)
    I = 2.9 / 150
    I = 19.333... mA - doubtful you'd be able to see the difference in intensity between 19.3 and 20mA.

    Now check the power requirement.
    P = EI, or Power in Watts = Voltage x Current
    P = 2.9v x 0.019333
    P = 0.0561 Watts, or 56.1 mW (rounded up)
    For long life, we double the power requirement before choosing the resistor wattage:
    0.0561 W * 2 = 0.1122 W
    That's more than 1/10 W, but less than 1/8 W. So, for this example, you could use a 1/8 W or higher rated resistor.
     
  3. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
  4. leftyretro

    Active Member

    Nov 25, 2008
    394
    2
    Actually most PIC type I/O pins can source or sink up to around 20ma, so a switching transistor is not really required just to turn off and on a normal LED. A current limit resistor is still required.
     
  5. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Perhaps, but any loading is good to avoid in the long run. Goes under the heading of prevention, if the output is weak for whatever reason then it will not put it under any strain.
     
  6. mattieg

    Thread Starter New Member

    Nov 28, 2008
    8
    0
    That does the job nicely. I went with using a switching transistor incase. Thanks for all your quick posts.
     
  7. mattieg

    Thread Starter New Member

    Nov 28, 2008
    8
    0
    Could this also be used if the cmos output needed to drive the input of another device?
    If so I was going to use a blue LED and using the calcualtions above I got a resistor value of 27ohms and power of 18mW. Will this be ok?

    Just one more question I promise, when selecting the transistor to use what parameters do I need to worry about?
     
  8. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Yes, as long as you don't exceed the current rating of the I/O pin.

    What are the specifications for your blue LED? If it's 4.2v @ 30mA, that would be about right.

    Well, driving just a few LEDs isn't much current. A 2N3904, 2N2222 or 2N4401 would all work just fine for sinking current from a half-dozen LEDs.

    Of those three, the 2N4401 has the highest gain, then the 2N3904. The 2N2222 can carry the most current, then the 2N4401.

    If you are driving separate transistors, they need their own base resistors.
     
  9. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    A PIC is made with high speed Cmos the same as 74HCxxxx ICs.
    The max allowed output from one output is 25mA and only a few are allowed simultaneously.
    The datasheets for Texas Instruments 74HCxxxx ICs shows a typical voltage drop of about 1.1V when the load draws 25mA. A logic high is 3.5V or more so it just makes it.
     
Loading...