Transistor for LED Cube Project Help!

Discussion in 'The Projects Forum' started by flipture, Feb 9, 2012.

  1. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Hello, first let me mention I've been searching and reading for over a week to try to understand what I need here and am still having a little bit of trouble. I do understand much better already tho!

    I'm using a 2N3904 transistor to switch the ground for the LED's in my light cube. I've got blue led's with 100Ohm resistors on the positive side before the LED.

    My question is...

    What value resistor do I need on the switch leg (middle leg, still learning all the terms, sorry) to switch the transistor open so it can flow freely to ground?

    I've found a few formulas but theyre different and i'd like to understand why i'm doing what i'm doing, not just adding numbers...

    I'm getting stuck trying to calculate the resistor I need to use to obtain full saturation (I believe this means that the transistor is open as much as it is able to?) so current can pass through freely when its switched on.


    My source voltage is coming from my arduino currently (soon to be an AVR chip but just trying to start simple as i'm learning) and is 3.3V.

    Here are the values that I've gathered...
    For the 2N3904
    Low Current Max 200MA
    Low Voltage Max 40V
    Vce(sat) 0.2 (i believe this is correct? Just learned what this is last night...)

    LED Specs (blue 5mm)
    3.0-3.2 forward voltage
    24mA current

    Arduino Power Output
    3.3v @ 50mA

    I would like to run 20mA through each LED and only one will be lit at a time.

    Please let me know if i'm unclear about what i'm asking or if I need to find any other values to get the calculations i need. I'm a bit of a newb but very driven to learn and don't mind reading and searching!!
     
  2. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Not sure if this helps but this is what i'm trying to do, but simplified. I have it working with this 220 Ohm resistor but I think i've burned up a couple of transistors trying this without that resistor.

    I see some setups with a ground switching transistor where there is an added resistor 10 times the one that goes to the middle but it leads from the middle to the output (emitter i believe). Not sure I need this?
     
  3. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Also, this is what i'm going off of... If you look at the right side, ignore the chip and pretend there is an arduino's outputs controlling these leads instead with 3.3v.

    Trying to find value for R18, R19, R20 and R21.
     
  4. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    The circuit has the LEDs connected to the collectors, not the emitters.
    Simply use Ohm's Law to calculate the resistor values:
    1) 20mA load.
    2) The base current must be 1/10th the collector current for a saturated transistor used as a switch. Then the base current must be 2mA.
    3) The base voltage will be 0.7V when the transistor is turned on.
    4) The voltage across the resistor will be 3.3V - 0.7V= 2.6V.
    5) Ohm's Law calculates 2.6V/2mA= 1300 ohms which is a rare value. Use 1200 ohms or 1500 ohms.
     
    Last edited: Feb 12, 2012
    fyerman01 and flipture like this.
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Start with an 8 LED "cube", 2 layers of 4

    Easy to whip up and get going in under an hour, and you get the concept down for the values needed, as well as what connections go where.

    The 2x2x2 will also help you practice soldering to make an 8x8x8.

    I wouldn't suggest going for an 8x8x8 straight off if you haven't built one before. The construction itself is a bit picky, a small error gets big as the structure grows. Make a jig on 20mm centers, use 3mm LEDs so there will be more 'space' between LEDs, and you won't run out of room if you get shipped LEDs with only 20mm cathode legs (24mm anode legs).
     
    flipture likes this.
  6. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    First of all, thanks for the replies!! Audioguru, I'm about to go through your post and make sure I understand it all...

    thatoneguy, you're right about starting small! I actually started with a 2x2, built a couple of 3x3's, then started testing transistor setups (this is kinda where I got stuck).

    I'd already built a 4x4 cube but had nothing to power it so this is what I'm playing with now. Please see the video below to get an idea where I'm at. I ran through a couple of formula's and ended up with 220Ohm resistor for R1 using 3.3v from the arduino which seems to work great. Maybe I got lucky? I looked at the formula again and not quite suer what I did as I was up extremely late lol.

    Regardless, I wired it all up and got it working with my arduino today!! Found some arduino led cube code that let me use the analog inputs as outputs and it fired right up!

    Here's the video...

    The formula that I found was on this forum (which is a big reason I joined up and posted).

    Here is what I did...

    R1 >= (vsupply - (vf_led - vce_sat)) / Desired Current
    R1 >= (3.3 -(3.2 - 0.2)) / 20mA
    R1 >= (3.3 - 3.0) / 20
    R1 >= .3 / 20
    R1 >= .015

    This is where I think the lack of sleep got to me...

    3.3v / .015 (not sure why i did this)
    This came out to 220 which looked like a Ohm rating so I tried one and went for it and it worked!!

    I also tried a 1k Ohm resistor and the LED was way too dim so I figured I was close... How I got there? I'm not quite sure. I would really like to understand completely.

    Audioguru, if I'm really supposed to be using 1k (ish) resistors, then why would the led be so dim? Did I possibly provide incorrect values somewhere? Maybe I'm not taking into account that I have a 100 Ohm resistor before the LED's?
     
  7. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    I think your LED is dim because either you mixed up the emitter and collector of the transistor, because you are powering the LED from 3.3V instead of the higher supply voltage they need or because the LED is not turned on long enough.
    Look at the datasheet of the 2N3904 to see which pin is which.

    Your arithmatic does not make sense:
    1) It seems that you are wrongly calculating the current-limiting resistor for the LED which connects between the supply voltage for the LED and the LED.
    Instead you are supposed to be calculating the value for the resistor between the 3.3V Arduino and the base of the transistor so the LED voltage (Vf_LED) IS NOT USED, instead the transistor's base-emitter voltage is used.

    The base resistor is calculated like this:
    1) The Arduino output is 3.3V.The base-emitter voltage is 0.7V. The base current must be 1/10th the LED current. The wanted collector current is 20mA so the base current and current in this resistor is 2mA.
    2) (3.3V - 0.7V)/2mA= 1300 ohms. A 1300 ohm resistor is rare so use 1.2k or 1.5k.

    The "resistor before the LED" is its current-limiting resistor and it is not "before", instead it is in series with the LED:
    1) Your LED is actually 3.2V (an LED has a range of forward voltages), its supply voltage is 5V and the typical saturation voltage for a 2N3904 transistor at 20mA is 0.1V.
    1) (5V - 3.2V - 0.1V)/20mA= 85 ohms. If 100 ohms is used then the current is (5V - 3.2V - 0.1V)/100= 17mA which will look the same as 20mA.

    Your vision is slow and sees an LED that is turned on for less duration than 30ms (0.03 seconds) as being dimmed.
     
  8. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    That's pretty cool for an arduino.

    Can you post the code for that inside code tags? (hit the # in advanced reply editor)
     
  9. kbyrne

    Member

    Dec 10, 2011
    84
    2
    To the author of this post: I just read a post by www.Jameco.com Electronics.
    Call 1-800-831-4242 and request a free catalog and ask to receive their e-mails. They have a hobby corner with cube videos. kits just like your attachment. There are links to other videos also. A link to www.instructables.com is also there but a fee to join is required. Good site and worth checking out for cube designs with a micro chip. Have been looking at this project as I like LED'S. Hope this helps
     
  10. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Instead you are supposed to be calculating the value for the resistor between the 3.3V Arduino and the base of the transistor so the LED voltage (Vf_LED) IS NOT USED, instead the transistor's base-emitter voltage is used.

    I'm still a tad confused on this. Is it that since i'm using a resistor *in series* :) that the values change? In other words I didnt' take account for the fact that I was using this resistor in my calculations? I was thinking it was ok since I am using the resistor to get the current to around 20mA.

    If I were to use this forumula would I need to do away with the resistor in series with the LED and simply use the one LED "before" the transistor to do all the work? Or does this have nothing to do with it at all due to the fact that I'm getting the LED its 20mA that it wants?


    The "resistor before the LED" is its current-limiting resistor and it is not "before", instead it is in series with the LED:
    1) Your LED is actually 3.2V (an LED has a range of forward voltages), its supply voltage is 5V and the typical saturation voltage for a 2N3904 transistor at 20mA is 0.1V.
    1) (5V - 3.2V - 0.1V)/20mA= 85 ohms. If 100 ohms is used then the current is (5V - 3.2V - 0.1V)/100= 17mA which will look the same as 20mA.


    Does this mean i should be running 5V to the circuit instead of 3.3? does that matter?

    I follow you on saturation voltage for 2n3904 at 20mA being 0.1V, so I need to make sure to make sure the base of the transistor is getting 20mA and 0.1V, correct?

    Maybe I don't understand where the 5V part is coming from...

    Thank you SOOOO much for your help and patience, i greatly appreciate it. I'm pretty new but eager to understand and learn fast!
     
  11. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    Is the PIC output port enuf to source the desired current.
    I see that the PIC ports are driving the LED string.

    Why is a transistor needed to sink the led current if the PORT is sourcing.
    Doesn't the driving port need a transistor to amplifier the LED current.

    If it is from insrtructables, I am not surprised.
     
  12. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The port is enough because there are two ports driving one "plane" at a time, so the transistor needs to sink that, then the trnsistor is switched to be the cathode for the next "plane" and the x,y LEDs are lit. So overcurrent is only on the cathode side.
     
  13. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Thanks! Sure, I'll post it as soon as I get home from work. I had to find one that let me use the analog ports because the standard arduino programs that I found looped through the ports using number++ which doesn't work well with A0 :).

    I actually have placed two orders already from Jameco! They have tons of great stuff!! I will have to check out their hobby corner... I bought a kit for one of my 3x3x3's but from here i'm learning how it all works and designing it all from scratch using what i've learned.

    I also learned a ton from instructables! Most of the DIY's that I based this off of were from there...

    My microcontrollers will be coming in today and my chips for expanding outputs arrived yesterday so i'm pretty excited! THanks for the tips!
     
  14. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    You do not understand the BASICS of electronics.

    There are TWO resistors. Don't mix them up.
    R1 limits the base current of the transistor and R2 limits the collector current of the transistor which is also the LED current.

    Of course the circuit will not work if the supply is only 3.3V because then R2 has no voltage across it then has no current and the LED also will have no current. An LED with no current does not light.

    Nobody makes a "3.3V" LED, some will be 3.1V and others will be 3.6V or 3.8V. Yours is probably "typically" 3.3V but you can't buy a typical LED.
    Without a current-limiting resistor and a 3.3V supply then obviously an LED with a voltage lower than 3.3V will burn out and with a voltage higher than 3.3V will not light.
    You need some voltage across the current-limiting resistor.

    Don't mix up the base current and the collector current. You want the collector current to be 20mA then the base current must be 2mA for the transistor to saturate well.
    The value of a resistor is calculated with the voltage across it divided by the current needed in it.
     
  15. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    So to your first statement, I went out and bought an electronics book tonight :).

    I'm reading and will probably be back with questions but hopefully a bit more knowledgeable...
     
  16. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Thanks for the diagram also. I realize i should probably be calculating with 5v as the output pins of the arduino provide that voltage...

    I'm going to try it on my board with 1 led and see if i can get it right.
     
  17. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    There is a very well written electronics book for FREE at the top of the screen, Start with "Vol. I - DC" and work your way through, it has some math in it, but if you aren't good at math, you can still get the idea of how everything from light bulbs to logic circuits work.

    It's by far the most thorough book on electronics for free, and there also MIT EE Videos that cover a lot for free as well. Search YouTube for "MIT Open CourseWare" to get the videos, 100% complete lectures for about 2 semesters of EE classes and physics.
     
  18. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    Awesome, I'll check it out. I believe I'm a good bit more caught up after picking up this book. I'm pretty good at math so I'm not too worried about that.

    I'll definitely check out those videos as well. I love physics stuff too so that sounds really interesting.

    I just got a few microprocessors in and assembled my USBTinyISP. Got it to erase the chip so now I just gotta make it run an led cube... Got some shift registers as well. Need to
     
  19. flipture

    Thread Starter New Member

    Feb 9, 2012
    17
    0
    So I think I figured it out. I found i'm using 5v so I'm using a 2.2k resistor to the base of the transistor and no resistor from the other 5v lead through the LED to the transistors emitter. Then the collector goes to ground. Led looks bright but not too bright!

    I did...

    R1 = 5v - 0.7V = 4.3
    R1 = 4.3V/2mA = 2.15 (2150 Ohms)
    R1 = 2.1k (ish) Ohms...

    Before I didn't understand that the transistor controlled the current for the LED and my other resistor wasn't needed...
     
  20. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    You figured out how to connect the transistor BACKWARDS!

    It is an NPN transistor so its emitter goes to ground (not its collector) and the LED with a very important series current-limiting resistor connects between the collector (not the emitter) and +5V.

    Since the supply is only +5V then the backwards transistor will not blow up, instead it will conduct a small current through the LED.

    Here is what happens if you connect the transistor correctly but without a current-limiting resistor:
     
    flipture likes this.
Loading...