need minimum resistor value for max led brightness

Discussion in 'The Projects Forum' started by s3b4k, Oct 5, 2011.

  1. s3b4k

    Thread Starter Member

    Feb 15, 2010
    38
    0
    the microcontroller i am using is atmega8 and led is liteon green led(part#LTL-1CHG). At Port B1 is where the resistor and led are basically i need help knowing what is the minimum value of the resistor i can use to have the maximum led brightness I used 100 ohms should i go higher or lower
     
    Last edited: Oct 5, 2011
  2. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    What is the maximum current your microcontroller can source?
     
  3. s3b4k

    Thread Starter Member

    Feb 15, 2010
    38
    0
    well the max current for the led is 30 mA. I attached the atmega8 datasheet not really good at reading it
     
  4. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    At an operating voltage of 5V (my assumption), the maximum current consumption of the LED is 30ma with a Vf maximum 2.6V, which would translate to an 82 ohm resistor. That's the top end, which is sure to shorten LED life.

    At an operating voltage of 5V, and a more conservative 20ma with Vf of 2.1V, that would call for a 150 ohm resistor.

    So, with the 100 ohm resistor, you are already close to the maximum current. I doubt seriously that you would be able to see the difference if you dropped the resistance to 82 ohms, and I would be surprised if you would notice if you increased the resistance to 150ohms. Personally, I try to use the lowest current rating (which is the highest resistance) that produces acceptable brightness, but hey, it's your LED. :D

    BTW, according to a quick look at the Atmega datasheet, the I/O pins can apparently source 40ma.
     
    s3b4k likes this.
  5. s3b4k

    Thread Starter Member

    Feb 15, 2010
    38
    0
    thanks mate really helpful

    btw is this for active high or active low setup or would it be the same?
     
    Last edited: Oct 5, 2011
  6. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    s3b4k likes this.
  7. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    If the LED is wired as shown in the schematic, it will light only when PB1 is high. If that doesn't answer your question, I don't understand the question.
     
    s3b4k likes this.
  8. s3b4k

    Thread Starter Member

    Feb 15, 2010
    38
    0
    the question i was trying it ask is if i changed the configuration to have active low on PB1 will the resistor still be the same value as you say?
     
  9. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,871
    1,394
    Yes, the resistor value would not change; the current flows in the opposite direction, but it's the same amount of current. (And of course the LED would have to be reversed and tied to Vcc.)
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    First, you look at the datasheet for the part.
    Here it is: http://media.digikey.com/pdf/Data Sheets/Lite-On PDFs/LTL-1CHG.pdf

    Absolute Maximum continuous forward current is 30mA
    Forward voltage (Vf) is 2.1v typical, 2.6v maximum @ 20mA.

    You are using a 5v supply. 20mA is really quite a bit of current for a uC's I/O pin, so you really should use a driver transistor.

    If you wish to know the real Vf of your particular LED at the rated current, you will need to measure it while current is flowing through it; preferably very close to 20mA.

    One easy way to do that is to use a 12v supply with a 470 Ohm or 510 Ohm resistor in series with your LED, or a couple of 1k Ohm resistors in parallel wired in series with your LED, and then measure the voltage across your LED.
    12v-2.1v = 9.9v
    9.9v / 470 Ohms = 21.06mA
    9.9 / 510 = 19.4mA
    9.9 / ((1k || 1k)/2) = 9.9 / 500 = 19.8mA
    All of those are close enough for the test.

    Once you get the Vf of the LED, then you can calculate:
    Rlimit >= (Vcc - Vf_LED) / Desired_Current
    You're using 5v for Vcc, and your Vf might be anywhere between 2.1v and 2.6v.
    Let's just say it's 2.1v for now.
    Rlimit >= (5v - 2.1v) / 20mA = 2.9 / 0.02 = 145 Ohms.
    You then need to look at a table of standard decade resistance values.
    There is one here: http://www.logwell.com/tech/components/resistor_values.html
    Bookmark that page.
    Looking at the green E24 columns, you will find that 145 is not a standard E24 value, 130 is too low, and 150 is the next higher value.

    Let's see what your current will be if you use 150 Ohms:
    I = E/R
    I = (5v - 2.1v) / 150 = 2.9 / 150 = 19.333mA; this is good.

    19.333mA is really too close for comfort to the maximum current allowed for I/O pins on microcontrollers. For reliability, you really want to stay well below the maximum specification.

    You need a transistor driver. I suggest a small signal NPN transistor, like a 2N2222, 2N4401, or 2N3904.

    You then need to calculate the resistance needed for the base of the transistor.
    Rbase = (Vin - Vbe) / (Ic / 10)
    where:
    Vin = the voltage input to the base resistor
    Vbe = the voltage on the base of the transistor when current is flowing through the base to the emitter; 0.7v to 0.8v are pretty typical values.
    Ic = the desired collector current.
    Your Vin is 5v, we'll use 0.8v for Vbe, and Ic is 19.334mA as we calculated above (current through the LED and the limiting resistor)

    Back to the formula: Rbase = (Vin - Vbe) / (Ic / 10)
    Substitute: = (5V - 0.8V) / (19.334mA / 10) = 4.2 / 0.0019334 ~= 2172.34 Ohms.
    Looking back at the standard decade table for resistance, you see 200 and 220 are standard values. Multiply 220 x 10 and you have 2200 Ohms, or 2.2k - that is close enough (it's a decade table; you multiply and divide the numbers shown by powers of 10).

    Looking back at an intermediate result, we see that Ic/10 = 1.9334mA, which is the current required from the I/O pin to turn on the transistor. If our desired collector current were a lot higher, say 200mA, our Ib would need to be ~20mA, which is again really too high; you want to keep the maximum I/O current to ~10mA or under for best reliability; so ~100mA is about the practical limit for a single BJT transistor driver - above that, and you should look at using logic-level MOSFETs, Darlington transistors, or a pair of transistors - one used as an emitter follower, the other as a saturated switch.

    You should also calculate the power requirements for the resistors.
    Whatever you get for the result from the power calculation, multiply it by 1.6, and select a resistor rated for the result or higher, so that the resistor will stay nice and cool.

    So, here is how you will connect the driver up to the microcontroller:

    [​IMG]

    You could also use a small N-ch logic level MOSFET if you so chose.
     
    Last edited: Oct 6, 2011
    djsfantasi likes this.
  11. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,815
    835
    Sgt. - This is the most complete and clear explanation of how to perform the calculations necessary for a transistor driver that I have seen. Bits and parts have been explained in various posts and forums, but this describes the entire process well. :D
    Thanks,
    dj
     
  12. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Thanks, djs.

    I try to explain things sufficiently so that people can use the same process to get good results without having to ask a lot of questions. Just follow the steps, and it works. :)
     
Loading...