LED circuit using 16F628A microcontroller assistance

Discussion in 'The Projects Forum' started by ke5nnt, Mar 2, 2009.

  1. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    First I guess I should say that I'm new here. I've been dabbing in electronics for a bit now, since I got into Amateur Radio anyways. I've found this site to be quite useful, so I decided I'd join in on the forums. My name is Ryan, nice to meet you.

    Now that the introduction is complete, I found this little project online and decided to give it a try. I've always had an interest in creating emergency style lighting, this project looked fun. Here is a link to the youtube video I found this project on. A link to this guy's site is provided on the video (the site is in Dutch).

    [​IMG]

    Ok, there's the schematic, the hex code for the microcontroller can be found at the bottom of THIS PAGE.

    I built this with the programmed microcontroller using 2 different leds, both are 3mm, one red (Vf = 2.2V @30mA) one blue (Vf = 3.5V @30mA). The voltages coming out of the TIP50s on the board are around 7.5V which is too high for these leds, basically I'm trying to get this circuit to operate in a state where I can successfully string about 20 to 30 of each red and blue leds together on the "display board" in parallel and have everything come function the way its supposed to. I'm not entirely sure how this guy got the schematic he did.

    If anyone can either take a look at this, or build one up of their own and make suggestions, that'd be fantastic. I'd also be nice to get an explaination as to how you got the result you did so I can learn how you came to that conclusion (more knowledge for the noggin).

    In addition, if you have any links to, or a schematic of your own of any kind of led flasher like this, or one with multiple flash patterns that you wouldn't mind sharing, I'd love to try them out too.

    Let me know if you need any more information from me. Thanks for the help/suggestions.

    -Ryan
     
  2. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Welcome to the forum.

    Search this forum and you'll find there are plenty of examples provided by members. Some does not involve a PIC but uses only 555 timers. More important is they also show how the LEDs are stringed together.

    Regarding your current project, I have two points on the schematic to make.

    Firstly it is not clear why the original designer choose to use emitter followers to drive the LEDs. Secondly there is also doubt why he uses two 10K resistors on a single node at Pin#17 & #18. I think you can use just one 10K instead. The changes you should make is here:

    [​IMG]

    If you want to drive more LEDs, then you will need to use individual resistors to replace the existing single 560Ω LED resistor. With 12V supply, you can place several LEDs in one branch and then connect several branches to the collector of one TIP50. The 1A current rating of TIP50 can support many branches.

    Remember that each LED requires about 2~3.5V of voltage drop(depends on color) so in one branch you can have 5 red but only 3 blue LEDs in series, along with a current limiting resistor.

    If you want help in calculating the resistors value, just ask here.
     
  3. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Thank you L. Chung, I will make the changes as described and give it another go.

    Also, I will give the forums here a search for those schematics you mentioned.
     
  4. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Ok, I made the following changes, everything seems to be working ok. Didn't really understand why the TIP50s were there, so I removed them altogether.

    View attachment 7688
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Ack! :eek:
    Did you check the electrical specifications for that PIC's outputs?
    Maximum source/sink for any pin is 25mA.
    Maximum Vdd input is 250mA
    Maximum current sourced/sunk by PORTA and PORTB is 200mA

    Your blue LED has a Vf of 3.5v@30mA
    However, maximum current for it's supply pin is 25mA.
    If you're using 5v for Vdd, then:
    Rlimit = (5v - 3.5v) / 25mA = 1.5v / 0.025a = 60 Ohms. The next larger standard value is 62 Ohms. You can go higher if you wish, but not lower without risking damage to the uC.

    Your red LED has a Vf of 2.2v@30mA
    However, maximum current for it's supply pin is 25mA.
    If you're using 5v for Vdd, then:
    Rlimit = (5v - 2.2v) / 25mA = 2.8v / 0.025a = 112 Ohms. The next larger standard value is 120 Ohms. You can go higher if you wish, but not lower without risking damage to the uC.

    You will not be able to control more LEDs than you have now using just those two pins, without using a transistor or MOSFET to sink current.

    The TIP50's aren't really appropriate for this project, they are intended for high-voltage applications. You would be better off using a logic-level MOSFET or a Darlington transistor.
     
  6. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Yeah thanks SgtWookie, already working on modifying that problem. Realized the current sink issue and am working on a way to fix that with the ability to drive several leds. Thanks for the input. Like I said, pretty new to this kind of stuff so a huge learning experience is taking place.

    Best
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    If you want compact Darlingtons that'll handle up to 500mA, look at MPSA14's or 2N6426's; use a 2.7k resistor from the I/O pin to the base of the transistor.

    If you want to use several I/O pins, consider using a ULN2003 or ULN2803 driver IC. These IC's have (respectively) seven and eight Darlington pairs, are inexpensive (less than $1), can sink up to 500mA per channel, and don't require resistors for the input pins (they're already in the IC) - but you'll still need current limiting resistors for the LEDs. You might want to get several of these; they're very handy for various projects. The ULN2803's can be used for controlling pairs of small unipolar stepper motors, like if you wanted to build a robot.
     
  8. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    What do you think here? Will this work? Will I need to add a resistor(s) prior to inputting voltage into the Collector?

    By the way, it should be noted that in the end, there will probably be 25 to 30 of each color LED on this, so 50-60 total LEDs. Still in the market for leds so not sure what the exact specs of those will be, however, the leds I'm considering are 5mm type.

    Blue:
    Reverse Current (uA) : <=30
    Life Rating : 100,000 Hours
    Viewing Angle : 180 Degrees
    Absolute Maximum Ratings (Ta=25°C)
    Max Power Dissipation : 80mw
    Max Continuous Forward Current : 24mA
    Max Peak Forward Current : 75mA
    Reverse Voltage : 5~6V

    Red:
    Reverse Current (uA) : <=30
    Life Rating : 100,000 Hours
    Viewing Angle : 180 Degrees
    Absolute Maximum Ratings (Ta=25°C)
    Max Power Dissipation : 80mw
    Max Continuous Forward Current : 24mA
    Max Peak Forward Current : 75mA
    Reverse Voltage : 5~6V

    I guess now that I look at the specs on those, they're the same for each color...interesting, and it doesn't specify Vf. Around 3.3Volts I would guess if my math is right. P/I = E, .08/.024 = 3.3333

    View attachment 7695
     
    Last edited: Mar 4, 2009
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Usually, a reputable LED supplier will give minimum, typical and maximum Vf @ current specifications. Roughly 80% of the LEDs will be very close to the typical Vf; the remainder more towards the extremes.

    180° viewing angle? They'll look bright close up, but get some distance away, and they'll seem pretty dim.

    I would pass on those LEDs.

    Meanwhile, you have your connections messed up in your schematic.

    The emitters of the transistors get connected to ground.
    The bases of the transistors get connected to the I/O ports via 220 Ohm or larger resistors.
    The cathodes of the LEDs get connected to the collectors of the transistors.
    The anodes of the LEDs get connected to appropriately-valued current limiting resistors; blue = 62, red = 120.
    The other side of the current limiting resistors get connected to +5v.

    Also, you left out the normally-open switch between pins 17 & 18 and +5v. I don't know what the function of that switch is, but if you downloaded and programmed the PIC from the internet, it probably changes the pattern or does some other function. There must be a reason the original schematic had a switch there. Right now, the only thing R2 is doing is dissipating power.
     
  10. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Ok, thanks for taking the time to help out, your input is all really appreciated.

    I will make those connections correct as you suggested. The switch you see in the original schematic is only an on/off switch, I'm relying on the power connection for that function. More after work today...
     
  11. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    First, the schematic in post 1 is the original, taken straight from the original designers site. I've had several people look at that and give confused looks over various things, mainly the use of 2 seperate 10K resistors there off of pins 17 & 18 where they say just 1 could be used with no problem.

    Secondly,

    Could you explain this a little further for a newbie's understanding?


    Also, For StgWookie,
    Could you explain how you came to the resistor values you did, and also, the +5v source would come from the 5v output of the 7805?

    Best,
     
    Last edited: Mar 4, 2009
  12. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Please review the following changes:

    Connected Emitters to ground
    Connected Bases to I/O @ pins 6 & 7 (as a note to clarify, I realize I forgot to add the 220Ω resistors SgtWookie suggested here, I'll fix that.)
    Connected LED Cathodes to Collectors
    Connected Anodes of Blue LEDs (Vf3.2 24mA 80mW) in parallel to one 82Ω 3W resistor
    Connected Anodes of Red LEDs (Vf2.0 24mA 80mW) in parallel to one 150Ω 3W resistor
    Connected resistors to +5V power source @ 7805

    Each array of 30 LEDs (one side) draws 720mA from the TIP50 which is rated at 1A. 3W resistors should be sufficient for 30 x 80mW.

    Schematic below, comments more than appreciated. Thanks again,

    Best,

    View attachment 7708
     
  13. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    You do not have a resistor in the base line of the transistor,
    the base-emitter wil burn this way.(put a resistor of 1K or higher in series with the base).
    You are putting leds parallel with one resistor.
    This is also not a good practice as the leds may vary in Vf and the led with the lowest Vf will get the most current and burn,
    then the next Vf led will burn and so on.
    Each led should have its own current limiting resistor.

    Greetings,
    Bertus
     
  14. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    I did specify I was going to do that, SgtWookie suggested 220Ω, bertus suggests > or = 1KΩ... how are you getting these values, and what is the purpose of these resistors, to limit current into the NPN?
     
  15. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  16. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Read the text on LEDs, thanks. Made the following changes:

    Configured 30 Blue LED 3.2V 24mA in parallel each with own 82Ω 1/4W resistor.

    Configured 30 Red LED 2.0V 24mA in Series/Parallel each series with own 47Ω 1/4W resistor. Was really hoping there was a way to get out of having to use so many resistors, but if it can't be done it can't be done. Schematic below (starting to get large). Thanks for all the pointers/help, input appreciated.

    Best,

    View attachment 7715
     
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I already did. See my prior post (#5 in this thread).
    Of course - unless you happen to have another +5v source that shares a common ground.
     
    Last edited: Mar 5, 2009
  18. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You need resistors on the bases to limit base current; in this case you need to ensure that the 25mA limitation of the uC's I/O pins are not exceeded; since 25mA is an absolute maximum, I derated it to 20mA for safety.

    Vbe is generally 0.6v or higher.
    5v - 0.6v = 4.4v
    4.4v / 20mA = 4.4v / 0.02A = 220 Ohms.
    Therefore, the base resistors must be at least 220 Ohms.

    Since the specified transistor has a very low hFE, it needs a good bit of base current. Even with 20mA, you still won't put the transistors into saturation.
     
  19. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    You have to use so many resistors because you are using 5V to power all your LEDs. Why not use 12V instead?

    Please re-read what I have said about how many LEDs can be placed in series in post#2.
     
  20. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Thank you for drawing my attention back to that. I will certainly try it again that way, saving me some resistors.

    SgtWookie, thank you again for your insight, I find it quite beneficial the explanation you gave. I will know to make those calculations myself in the future.
     
Loading...