A Beginner's LED project

Discussion in 'Embedded Systems and Microcontrollers' started by darknys, May 19, 2008.

  1. darknys

    Thread Starter New Member

    Apr 24, 2008
    8
    0
    OK, so here's what I want to do: http://www.evilmadscientist.com/article.php/CylonOLantern

    The thing is, I want to make it very, very small. I have a 5mm window to shine LEDs out of. I have maybe 30 cc (2 cu. in.) to fit all of the components in. I might be able to put batteries outside this, but I'd prefer not to. I figure a 3v coin cell should drive it just fine. It doesn't need to last very long. I talked to the guy who made the original, and he suggested a microcontroller to save space.

    The problem is, I know nearly nothing. The only electronics stuff I remember is from Physics 112, about 6 years ago.

    I would post a diagram to show you guys what I'm thinking so far, but all the programs to make such things seem geared toward high-end CAD stuff and are very difficult to use. (At least for me) I've got some 0603 LEDs that should fit 5-wide into my window. I've got a PIC kit at a 12f675 to do the blinking. I don't have the foggiest how to code the damn thing, but I figure that's step 2.

    Step 1 is figuring out what the bare minimum number of components are and it what order I need to put them together. I figure I'll need a battery, my chip, 5 LEDs, and 5 resistors at the bare minimum.

    I'm a bit confused about how to calculate the resistance I'll need, because I don't know what effect the chip will have on the circuit. Also, I'm wondering about capacitance and fading the LEDs. In the original project, he added another resistor, a transistor, and a capacitor in what he called a 'low pass driver circuit.' Given my space limitations, that's right out. Is there any way I can get an equivalent effect with fewer components, or failing that, fake it in software with the microcontroller?

    Thank you for bearing with me on what would probably be a blindingly basic project for most of you.
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    First, stop apologizing.

    Second, try taking things in very small steps.

    I'm afraid that you have very high ambitions, but you are finding yourself way over your head without a life preserver.

    Having high ambitions is not a bad thing. However, attempting to leap from where you are to where you want to be is virtually guaranteed to be disasterous, without a great deal of education.

    While we are very willing to assist you along your path, we generally won't design things for you - that is for you to do. If you have specific questions, please feel free to ask. However, most general questions have already been asked, and answers can be easily found with an inquiry on a search engine. As things are now, your questions are rather broad and non-specific - even though you hinted at them.

    Example: "I've got some 0603 LEDs that should fit 5-wide into my window..."
    OK, I know what 0603 diodes are. However, what is their Vf @ rated current?

    You've posted more mysteries than answers. This is a forumn that needs facts in order to give relevant answers.
     
  3. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    The "Eagle Light" software is fairly easy to use. http://www.cadsoft.de/freeware.htm

    How will you squeeze 5 each 3mm LEDs into your 5mm window? Can you mount them in an arc them inside the box, sort of like an inside-out turret?

    Choosing the right resistor requires knowing the applied voltage, the voltage drop of the LED, and the current needs of the LED. So an early step is to choose your LEDs.
     
  4. mrmeval

    Distinguished Member

    Jun 30, 2006
    833
    2
    http://www.arduino.cc and some shift registers. I've not pushed this past 16 yet but it's trivial to do so it just takes more coding.

    If you follow the links you can use either shift register. I really don't see a brightness difference with either but the HEF chip could drive more LEDs without more parts. If I were to need more per pin I'd use a transistor and a resistor on each LED and just use the much cheaper 595 chip.

     
  5. darknys

    Thread Starter New Member

    Apr 24, 2008
    8
    0
    First off, I'm sorry for not being more specific. :D

    OK, now specifics. I'm working with a PIC 12F675, a 3V power supply, and 5 0603 LEDs. The specs for the LEDs from the manufacturer say 1.8-2.4v, 20mA. I'm not really sure what to make of the broad voltage range, or how to take it into account. According to the 12F675 datasheet, (if I'm reading it correctly) the high voltage output is Vdd-0.7, or 2.3V as things stand. Working with the 1.8V and 2.3V, the resistance should be about 33 Ohm to allow for a bit of a safety margin for the diodes.

    Now, I guess my questions are:

    1. Are my calculations correct, and what does that voltage range mean?
    2. Will I have to bump the circuit to 4.5V to drive it adequately? (i.e. 2.4V to the diodes)
    3. Can I make the transition between the different LEDs "softer" without adding a mess of components?
    4. Should I just let the wookie win, lest I get my arms ripped off?
    The diagram is as follows:
    [​IMG]

    Eagle Light is exactly what I was looking for. Thank you. Everything else seemed more oriented toward building ICs and processors. As for the squeezing, they're only 0.8mm tall, so I was hoping to mount them sideways. If the viewing angle won't allow that, I'll try your turret idea. I'd not thought of that, and it sounds interesting.

    I'm afraid I've already got the PIC chip and programmer. I'm hoping I have all the components I need and can avoid spending more money.
     
  6. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    As long as you are aware there are other ways of doing the same thing, some possibly better. PICs are great, but like the man with only a hammer for a tool, every job starts looking like a nail.

    When I saw your initial layout I thought you were going for the full 24 LEDs. I think everyone did. Light circuits are a common starting point for a lot of us (was for me!). Main thing is to have fun, the learning will take care of itself. I have several lightchaser schmatics in my library. Again, I suspect all of us do.
     
    Last edited: May 20, 2008
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I'm not familiar with the PIC12x series. I'm concerned about how much current they can source. I'll bet it's just a few milliamps. Trying to source 20mA for your diodes may cause it to overheat. They have weak internal pull-ups.

    I suggest that you investigate using ULN2003 or ULN2803 IC's; they are (respectively) seven and eight Darlington pair driver ICs. Each output can sink up to 500mA. They are cheap, at around $0.50 apiece. You could also use discrete transistors with 2.7k current limiting resistors on the bases, but that will mean more parts to deal with, and likely more expense. The ULN2x03's already have the resistors built-in. It doesn't get much easier or cheaper.

    The LED manufacturers generally give a "typical Vf" and "maximum Vf" along with the current specification. This is because individual LEDs can vary quite a bit in their actual Vf. If you want to be safe, you'll go with the lower of the two voltages.

    If you go ahead with either the ULN2x03 Darlington driver IC or discrete NPN transistors, you will be sinking current (providing a ground) instead of sourcing it. The transistors/Darlingtons's collector gets connected to the cathode side of the LED, then the current limiting resistor to the anode, and then V+.

    There will be a roughly 0.7v drop across the transistor or Darlington when it's conducting, so you'll need to subtract that from your voltage supply when calculating your limiting resistors.
    Rlimit = (Voltage Supply - Vf(LED) - Vdrop(transistor)) / I(LED)
    Rlimit = (3v - 1.8v - 0.7v) / 20mA
    Rlimit = 0.5/0.02
    Rlimit = 25 Ohms
    If you're using 33 Ohm resistors instead, then:
    I = E/R
    I = 0.5/33
    I = 15.15mA
     
  8. darknys

    Thread Starter New Member

    Apr 24, 2008
    8
    0
    I've had another go at the datasheet, and it seems that it will drive the LEDs adequately. The maximum current output/sunk by any one pin is 25mA, with a total maximum of 125mA.

    There's a lot I don't know about this chip, so I don't want to use my own say-so... I might let the magic smoke out. Does anyone know for sure?

    Sergeant, I just want to make sure I'm reading you, and the ULN schematic, correctly. I may have mixed up input and output... I wasn't sure if it was current input and output, or logic input and output. Anyway, with a ULN2003 the circuit diagram would look like this:

    [​IMG]
    And with either this setup, or the other, the voltage drop across the IC is 0.7 V, so 25-33 Ohm resistors either way.
     
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I downloaded a datasheet for the rfPIC12F675, but I didn't spot the current source/sink limits. If it says 25mA, you can go ahead and just sink the current right at the PIC. However, it's not a bad idea to use peripheral driver IC's, as it'll keep your CPU running nice and cool. It's easy to replace ULN2x03's, and they're cheaper than your uP.

    Yes, you hooked up the ULN2003 correctly. In one side, and out the other! Pin 9 is the common cathode for the internal clamping diodes. You only need to use that if you're driving inductive loads, like relays or motors. You just connect it up to Vcc, and it takes care of the EMF spikes for you. They're real handy IC's to have around.
     
  10. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    I was able to find the current source/sink specs on page 83, section 12. They are as have been noted in this thread. There is 25% headroom all around, so it should work.

    Darknys, for a "softer" transition between the LEDs, you might try playing with "pulse width modulation" in your software. A search on that exact term, and/or "PWM" will get you started.

    As for letting the Wookie win... well, it couldn't hurt, but it doesn't guarantee keeping your arms attached.:eek:
     
  11. darknys

    Thread Starter New Member

    Apr 24, 2008
    8
    0
    Thank you very much for your help, Sergeant. I will add the ULN series to my lexicon, but I think I'm going to remain with the bare PIC in the interest of simplicity and space. If it explodes, I will let you know so you can give me a well-deserved "told ya so."

    Thank you for the direction. This does seem like it will do what I want it to do. I had originally thought that I would 'flicker' the LED by toggling the pin on and off at some interval, every two or three iterations, during the delay cycle governing the overall transition from one LED to the next. After some reading, I've surmised that I should limit the frequency of the pulse width as much as possible to preserve LED life, correct? I think as long as I keep it above 16 or 20 Hz, the flicker should be imperceptible.

    Well, at this point the project is going along swimmingly. Now, it's time to take off the internet hat, and put on the code-monkey hat. I'll see what I can come up with. I think I'll have a testbed up soon, and I'll be back to report progress. (Either that, or I'll be back with a snipped of code, some tears, and my hat in my hand.)
     
  12. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    PICs are made with High-speed Cmos the same as in 74HCxxxx series. The max allowed output current is 25ma and if the IC has a 4.5V or higher supply it will try to have an output current into a red LED of 36ma to 42mA or more and will melt its internal transistors.

    Nobody says how little is the output cirrent is the supply is only 3.0V. In my 3V Ultra-bright LED Chaser project I have four 74HCxxxx inverters in parallel to make an output current of about 25mA when the supply is 3.0V.
    Test one yourself.

    The CR2032 battery is awfully small. It is spec'd with a current of only 0.2mA. Who knows if it will drive a single LED at 25mA for even 1 hour.
     
  13. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    Isn't that why God invented series current-limiting resistors?
     
  14. darknys

    Thread Starter New Member

    Apr 24, 2008
    8
    0
    I hadn't thought about the battery. After a bit of randoming around, I think perhaps a camera battery like the CR17345 might be more appropriate, unless someone has a better suggestion.

    As far as the rest, I'm afraid I'm not parsing it too well. I thought the resistors attached to the LEDs were the current limiting factor, and that would prevent any melting of anything. Is this incorrect?

    As I understand the output current rating of the chip, that is the maximum that can be pulled through that pin before things begin to cook. Now, I'm sure what all is going to cause frying on things of this scale, but usually sizzling is heat related. At a lower voltage than the rated maximum of the chip, pulling the maximum rated current shouldn't be a problem. W=V*I, as the man once said.

    Perhaps there is something I'm missing, and I should turn the original circuit on its head and sink the current into the IC instead of sourcing it out. (Wow, I'm picking up terminology fast.) This would eliminate any chances of current not being available due to the inner workings of the chip, and the input rating on those pins is symmetrical with the output.

    That last paragraph is right out into the realm of pure speculation.

    Please, if any of my logic or assumptions are wrong, correct me. I'm here to learn.
     
    Last edited: May 20, 2008
  15. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    I think Audioguru was speaking in generic terms rather than about your effort specifically. Only the Auld Duck himself knows for certain, of course.

    Limit each o/p to the 20mA the LEDs are rated for and you'll not need to worry about having any fries with your order.;)

    I looked up the CR2032. It packs about 220mAH. As Audioguru noted, it should not be asked to source more than 200mA. Your PIC needs 2 or 3 hundred mA, does it not? I concur the CR17345, with 1.3 to 1.5 AH and a sustained current of 1A is a much better choice.
     
  16. darknys

    Thread Starter New Member

    Apr 24, 2008
    8
    0
    The PIC itself should be pulling current on the microA scale. (Can I buy a mu?) I think this circuit will max out at 101 mA with everything active at once. If all goes to plan, that should never happen and my actual power consumption should be markedly less. It looks like the max the chip can pull is 3mA, and that's if you jack it up to 5V@20MHz and give it a slap on the ass.

    As always, I could be reading the datasheet incorrectly. It's on table 12.2 or 12.4. (I can't tell a difference between the two, except for upper temp range.)
     
  17. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    Interesting. I had simply worked backward from the 800mW figure, but I see now said figure has fine print attached. Darn the fine print, anyway!:cool:
     
  18. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    Nobody knows how little is the output current from a PIC when it has only 3V for a supply.
    The typical output current with a 4.5V supply is 36mA sinking and sourcing because it is almost symmetrical.
    The typical output current with a 6.0V supply is 48mA sinking and 64mA sourcing. Enough to cook the IC well done.

    With a 3V supply the output current might be too low or low enough so that current-limiting resistors are not needed.
     
  19. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    Have any idea what the o/p current max is with the 3V planned for this project?
     
  20. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Following on what Audioguru's been saying, and going back to the resistor calculation thing, since the PIC's output are CMOS, they're going to be rail to rail, and not have the voltage drop like BJT's would. However, the more current you try to sink or source from a CMOS output, the greater the voltage drop across the output device becomes.

    Before, we were figuring on 1.8v LED's with a 3v supply and a .7v drop in the Darlington, or:
    Rlimit = (3v - 1.8v - .7v) / 20mA = 25 Ohms
    But if we're starting from the rail:
    Rlimit = (3v - 1.8v - 0v) / 20mA
    Rlimit = 1.2/20mA
    Rlimit = 60 Ohms.
     
Loading...