Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 32

Thread: Teensy and LEDs

  1. #1
    Junior Member
    Join Date
    Aug 2018
    Posts
    18

    Teensy and LEDs

    Hi, I have a Teensy 3.5 and will be using it to create a simple button box for sim-racing, with about 23 buttons and 4 rotary encoders.

    And I also want to use 8 LED lights:
    1 of this type: https://www.banggood.com/19mm-Waterp...r_warehouse=CN
    2 of this type: https://www.banggood.com/19mm-12V-5-...r_warehouse=CN
    5 of this type: https://www.ebay.com/itm/Diffused-Gr...w7deAsc6rmJzeA

    Each LED will get its own IO-pin and a 150 ohm resistor (except the 12 V LEDs which I assume don't need resistors?), and 4 of the LED will be connected to one GND pin while 4 will be connected to a different ground pin (does it matter if I split them on two GND pins though?).

    Here is an approximate schematic.
    Click image for larger version. 

Name:	Oog7mCs.png 
Views:	1 
Size:	105.0 KB 
ID:	20143


    I have already tested those 12 V (car type) LEDs and they do light up fine. In the description of similar buttons on ebay it says they can be used in both low voltage and high voltage circuits, so I assume the same goes for those buttons on Banggood. I have no idea how many amps they draw though. The 5 "normal" 5mm LEDs are 20mA and 1.83.6 volt.

    Do you think I'll be able to use all those LEDs without issues? I just want to make sure I don't damage my Teensy 3.5.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	U6infur.png 
Views:	2 
Size:	78.0 KB 
ID:	20142  

  2. #2
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    With this setup, there is too much current draw from the digital pins of the Teensy.

    The max individual current draw for a single pin is 25mA for the 3.5, and the total current draw from all digital pins is 100mA max.

    Assuming 20mA for each LED and 8 of them, you are asking for 160mA.

    You may want to raise the resistor values (for example doubling them) and if needed replace your LEDs with high efficiency ones, which are very bright while drawing just a few mA.
    Last edited by XFer; 05-16-2020 at 11:04 PM. Reason: syntax

  3. #3
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Hmmm, what if I reduce it to 4 LEDs? Technically 5 but I'm making sure only 4 is lit at the same time.
    Can I be sure those car type LEDs are 20mA?

    Outside of that, what options do I have for powering 8 LEDs?

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    You could use transistors to switch them, that way the Teensy is just driving the transistor and not the LED. Google Arduino

    You could also use something like a 74hc245, there's several examples of an Arduino controlling LEDs with those.

  5. #5
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    4 x 20mA LEDs powered at the same time are within the specs. Just be sure there aren't other devices drawing current from digital pins.
    Or use a transceiver as suggested.

  6. #6
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Thanks for helping guys! I'm a bit of an Arduino noob so please bear with me.

    First of all, I'm really a noob when it comes to electricity. Can I use those car type lights at all? What if they draw a lot more than 20mA? Will I have to buy a multimeter and measure to be sure? As a side note, for the engine start button it says this "For load under 3 Amp, you do not need a relay with this switch." I have no idea what that means.

    Secondly, is using transistors or transceivers complex? I'm trying to keep this as simple as possible due to my inexperience. At the moment I have no idea how to connect either of those things. Is there a good place to read up on them that also have simple examples? Also, would I need an extra power source when powering 8 LEDs using transistors or a transceiver?

    Again, I really appreciate the help!

  7. #7
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    I would humbly suggest a bit of reading about basic electronics and Arduino-starter-lessons, before digging into more complex projects.
    LEDs, for example, are bit more complex than it may seem at first sight.

    For example: you talk about "12V car-type LEDs", but there's no such thing (even if advertised as such).
    A LED is current-driven, not voltage-driven.
    So you may want to, first, measure its voltage drop and brightness with various voltages and series resistor (without a Teensy).
    Then, you can easily figure out if it's OK to drive with a Teensy, and which R value is needed.

    Example: source a good 3.3V power input (which will fake a Teensy digital pin), prepare a breadboard with your LED and a series resistor (starting with say 100 Ohm).
    Connect and, with a good multimeter, measure and write down both the voltage drop on the LED pins and the voltage drop across the resistor.
    Take note of the brightness and color.
    Then replace the R with say 220, 470, 1K and repeat.
    This will tell you (and us) all it's needed to characterize your LEDs.

    About the need for an external driver: transistors are a bit complex at this stage. Transceivers are easier.
    You should not need an external power source: a Teensy 3.5 will happily put out 300mA from its "3.3V" pin.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,077
    First to answer a couple questions...

    Quote Originally Posted by whitestar View Post
    As a side note, for the engine start button it says this "For load under 3 Amp, you do not need a relay with this switch." I have no idea what that means.
    That's talking about the physical metal contacting parts inside the switch. They're big enough to conduct 3 amps. Think of the wires in your car. You need a huge wire between the battery and starter motor, because it draws massive current. But only thin wires are needed for controls and sensors. The more current something needs to conduct, the bigger the wire is needed. This info is trying to tell you how big the metal parts are inside the switch. If you want to turn on something that uses more than 3 amps, the switch wires are too small, so you're supposed to use the switch to turn on a relay (which would use less than 3 amps to turn on) and then be able to conduct much more (the relay should also have specs about its maximum current). But in practice, if you needed more you might just try to buy a switch rated for your needs rather than go to the trouble of having the switch turn on a relay.


    Secondly, is using transistors or transceivers complex?
    Transistors are moderately complex to use, but the main downside is they're very unforgiving of mistakes. They're small parts and the 3 wires look similar, so it's easy to get them mixed up. If you wire it up wrong, bad things happen. If 12V power is involved, bad things usually means Teensy destroyed.

    While many might consider this overkill, you might think about using a "solid state relay". They come in a variety of sizes, many very large. You probably want a small one that looks like this.

    Name:  ssr.jpg
Views: 106
Size:  9.4 KB

    The huge advantage of a solid state relay is it's easy to use and very forgiving of mistakes. They have 2 wires for input where you apply 3V or 5V, and the output is basically a switch. The really nice part is there's no physical connection between the inputs and outputs. Usually they are made with a LED and photo-detector inside. But you don't need to worry about how it works internally... you just put voltage on the input and the output acts like a switch. The isolation between input and output means there's no way for 12V to accidentally feed back into Teensy (well, unless you connect that wire to Teensy or your wiring comes loose - so do a good job connecting the wires).

    The downside of a solid state relay is they cost a few dollars, which is pretty expensive compared to a few pennies for a common transistor like 2N3904 or 2N2222.

  9. #9
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Dang, this got complicated fast!

    Well ok, for now I'm going to use only this LED: https://www.banggood.com/19mm-Waterp...p-1181088.html
    Surely that alone can't be so power hungry that it damages my Teensy. I looked up similar lights on ebay and it seems they might use about 50mA.

    Later I'll buy resistors, a multimeter and this power supply (english manual here) to test voltage drop on a breadboard, as suggested. I assume that psu will be good enough?

  10. #10
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Quote Originally Posted by XFer View Post
    I would humbly suggest a bit of reading about basic electronics and Arduino-starter-lessons, before digging into more complex projects.
    LEDs, for example, are bit more complex than it may seem at first sight.
    I would say I have just enough knowledge about Arduino to make a button box. I already made one smaller before and it worked fine. This is the same, just bigger. Have a fair bit of background in VB and VBA programming and a tiny bit C++ and Java. So the programming part was fairly quick to grasp the basics of. Soldering was quick to learn as well, even though I suspect it would take experience to get really good at it. The biggest hurdle for me, as you say, is electronics. I have a lot to learn in that apartment.
    For example: you talk about "12V car-type LEDs", but there's no such thing (even if advertised as such).
    Yes, I was a bit inaccurate. I meant the type of pushbutton, not the LED specifically.
    Source a good 3.3V power input (which will fake a Teensy digital pin), prepare a breadboard with your LED and a series resistor (starting with say 100 Ohm).
    Connect and, with a good multimeter, measure and write down both the voltage drop on the LED pins and the voltage drop across the resistor.
    Take note of the brightness and color.
    Then replace the R with say 220, 470, 1K and repeat.
    This will tell you (and us) all it's needed to characterize your LEDs.
    Thanks! I'll get back to you on that once I have done the testing. Might need some help with the testing though. [/QUOTE]
    You should not need an external power source: a Teensy 3.5 will happily put out 300mA from its "3.3V" pin.
    Ok, but that pin doesn't work as an IO-pin, correct? I can't use it to switch a light on and off at will?

    Thanks again for helping!

  11. #11
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    Quote Originally Posted by whitestar View Post
    Well ok, for now I'm going to use only this LED: https://www.banggood.com/19mm-Waterp...p-1181088.html
    Surely that alone can't be so power hungry that it damages my Teensy. I looked up similar lights on ebay and it seems they might use about 50mA.
    50mA is too much for a single pin.
    As I wrote, the maximum is 25mA for a single pin, 100mA for all pins together (sum of all draws from all pins).

    I assume that psu will be good enough?
    Yes, beware it's dual-voltage: 5V fixed on one rail (don't use) and selectable between 3.3V and 5V on the second: be sure to select 3.3V for the second rail.

    EDIT: the "3.3V" pin is a fixed power source/sink only, you can't control it.

  12. #12
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Quote Originally Posted by XFer View Post
    50mA is too much for a single pin.
    As I wrote, the maximum is 25mA for a single pin, 100mA for all pins together (sum of all draws from all pins).
    Right, sorry!
    Ok, so what you want me to test is which resistor to use to get the current in the circuit down to 25mA or less (assuming that the LED uses more than 25mA)? And to see if that is enough to light the LED?

  13. #13
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    Yes, correct.

    To put into perspective: I have a number of LEDs which are advertised for 15-20mA.

    Actually, when driven with 5mA (!) they are just as bright (to my eye at least) and have the side effect of remaining much cooler (which prolongs their life).

  14. #14
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Quote Originally Posted by XFer View Post
    To put into perspective: I have a number of LEDs which are advertised for 15-20mA.
    Actually, when driven with 5mA (!) they are just as bright (to my eye at least) and have the side effect of remaining much cooler (which prolongs their life).
    Ah, nice! So that means I could potentially use all 8-10 LEDs that I wanted in the first place.

    Thanks for your time and patience, I really appreciate it! I've already learned a lot just by reading your answers and I'm sure I'll learn a whole lot more after doing this testing.

  15. #15
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    You're welcome! Keep asking.

  16. #16
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Ok, I've done some testing now. This was my first time with a multimeter so I'm not sure if I did it right.

    First I made sure I used 3.3 volts on the psu. I flipped the switch on the psu to 3.3 and used the side where it said only VC (on the other side it said 5V). Then I measured the voltage to exactly 3.30 with the multimeter probes. The multimeter was set to 20V.

    When it says "mA measured over" in the table below it means that I put the red probe from my multimeter on the LED anode and the black probe on the LED cathode, then read the value. The multimeter was set to 200mA.
    Same procedure for for volt, which I measured over both LED and resistor. The multimeter was set to 20V.

    First some noobish observations : When I measured mA on the LEDs the light disappeared. I'm assuming this was because I let the current flow "outside" of it and through my multimeter instead?

    Here is a table with the values I measured. Did I do it correctly?
    Click image for larger version. 

Name:	y0qhRnt.jpg 
Views:	3 
Size:	66.0 KB 
ID:	20186

    Sorry for not being completely consistent. The blue diffused LED is the only one I measured with all resistor values.

    Assuming I did this correctly; does it mean that if I use a 330ohm resistor then I can use in theory 10 of those LEDs, since the total budget is 100mA and they seem to draw 10mA when using that resistor value?
    My second assumption would be that it seems that the LEDs in those "car type" pushbuttons draw the same amps (22.2) that my "normal" LEDs do. They don't appear to draw 50mA which I first thought.

  17. #17
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    Hi!

    Quote Originally Posted by whitestar View Post
    When it says "mA measured over" in the table below it means that I put the red probe from my multimeter on the LED anode and the black probe on the LED cathode, then read the value
    Note that I did not suggest measuring mA, only V.
    This is because the mA measure can only be indirect (short of inserting the multimeter in series).
    Not a problem: we obtain the current by your measure of V across the resistor, because we know the R value.

    Before anything else: by any chance, is it an Excel table? This would save me the chore of manually copying all the values.

    When I measured mA on the LEDs the light disappeared. I'm assuming this was because I let the current flow "outside" of it and through my multimeter instead?
    Yes, that's why we evaluate the current from the V measure across the resistor.

    Assuming I did this correctly; does it mean that if I use a 330ohm resistor then I can use in theory 10 of those LEDs, since the total budget is 100mA and they seem to draw 10mA when using that resistor value?
    That's the idea, but first we need to compute the actual mA from the voltage drop across the resistor.
    If you have the Excel table, this would help, otherwise I'll make one for you.

  18. #18
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Ah yes here is the Excel table: http://www.mediafire.com/file/7s700r...olts.xlsx/file.
    I hope the link works. I was unable to attach an Excel file on this forum.

    The decimal separator for my region is a comma, but I assume that will change automatically to a period when you open the file with your regional settings.

  19. #19
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    New version here:
    https://www.dropbox.com/s/57nbmr2pe2...ts_2.xlsx?dl=0

    BTW my country uses comma too, but I routinely force the decimal point (I dislike the decimal comma!)

    Just to be sure, you may want to re-assess voltage drop across the resistor by selecting "2V" instead of 20V

  20. #20
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Downloaded, thanks.
    Ok, so how do I interpret those values you computed? Where do I go from here?

  21. #21
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    Those values are the real current (mA) which flows across your LED in each situation (assuming the resistor voltage you measured is right).
    As you see, it's quite smaller than anticipated, which is very good news.
    Just pick the resistor-LED combination which most suits you.

  22. #22
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Aha! That is good news! So the 20mA rating is probably just the max the LED can handle before it fries then?
    But ok, I will double check the voltage drop with the multimeter set to 2V first, and measure all the LEDs I'm planning to use. At least it's good to know that I can use 4 LEDs without a problem.

    These results would also kind of explain the values I see in Tinkercad, which now seems to simulate quite well current and voltages.
    Click image for larger version. 

Name:	FnRJrzO.png 
Views:	2 
Size:	136.4 KB 
ID:	20197

    This was just an example value. If I increase the resistor value to 62 that warning goes away, which means that less than 20mA flows through. Using a value of say 150ohm then should put the current well below 20mA, which coincides well with my/your findings, don't you think? Of course, it doesn't say the rating for that simulated LED, but based on the voltage drop on the resistor (measured with a virtual multimeter which is also available) it looks like a clear LED with 1.8-2.4V rating, same as my Orange LED.
    You may have already used this yourself but just in case: https://www.tinkercad.com/circuits.

  23. #23
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    Now you have a comprehensive view of the situation.
    Yes, 20mA is probably the maximum current before the LED dies from overheating. They are quite sensible to that, so the cooler the better.
    Have fun with your project!

  24. #24
    Junior Member
    Join Date
    Aug 2018
    Posts
    18
    Thanks a million, XFer, you are a star! If there were some kind of awards on this forum you'd be getting a bunch from me.

    If I may, just one more tiny thing....kind of off-topic though:
    In my button box I will have the resistors soldered to the LED pins (or with a small piece of wire in between). I was just wondering how heat resistant these resistors and/or LEDs are. I usually solder with 340 degrees Celcius, is that too much? It seems people recommend about 260 degrees for soldering resistors to LEDs.
    To test that the resistor works as it should after soldering, should I hook it up to the psu and measure voltage drop again? Or can I assume it works as long as the LED lights up?

  25. #25
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    336
    Thank you, but I have to confess I'm the least knowledgeable of all the Teensy forumers!
    There are real geniuses around here (not to mention Paul Stoffregen Himself, of course).

    As I said, feel free to ask! Don't worry. At worst, you may not get an answer in awhile (there are times when me and others may be too busy to have a look at the forum in awhile. I've been away for many weeks).

    Heat resistance.
    LEDs suffer prolonged heat (heat harms their efficiency and lifespan), but in general can withstand some punishment when soldering.
    Never managed to fry a through-hole LED while soldering; same for resistors. Fried a capacitor as a kid.
    So I would not worry about that: if it lights up, it's OK.

    As for solder iron temperature: I have it at 320 C (I use tin with lead) and works very well with 0.5mm tin. I don't use 1mm tin anymore, too thick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •