Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 13 of 13

Thread: Teensy 3.0 with LED array

  1. #1

    Teensy 3.0 with LED array


    I'm new to the forum as well as electronics in general.

    I've been in touch with Paul Stoffgren about this, but thought I would bring my discussion to the forum for public searchability.

    I'd like to power an array of fading LEDs with the Teensy. The array will not be on a matrix, but rather on a string that I've soldered together. So far, I have them soldered in parallel. I may upgrade to an LED strip within the next few days, specifically the LPD8806. For the time being, however, I'll be sticking with my self-made string of LEDs.

    Since my knowledge is very rudimentary, I don't know the best way to connect the LEDs to the Teensy or which code to use. I've been searching for "fading array arduino" on Google but the results are surprisingly unhelpful. We all have to start somewhere



  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Do you have a schematic or even a photo of how you've built these LED strings? Knowing how they're physically connected would really help to give you accurate advice.

  3. #3
    sure thing! here you go:

    Click image for larger version. 

Name:	photo2.jpg 
Views:	204 
Size:	54.0 KB 
ID:	347Click image for larger version. 

Name:	photo1.jpg 
Views:	179 
Size:	65.7 KB 
ID:	348

    (apologies for the delay, the web uploader for this page doesn't seem to play well with safari so I moved my images to a hosting site)

  4. #4
    Join Date
    Dec 2012
    Adelaide, SA
    You do want to fade them all on and off at once?

    You'd probably use a (power) MOSFET to drive the LEDs, via a PWM output on the Teensy.

    Basically drive the MOSFET from a PWM out of Teensy, via a resistor to limit current (1k or so perhaps?). Source of the MOSFET to GND. You'll also want a largish resistor between Gate and Source, 100k or thereabouts. The cathodes (-ve) of the LEDs (via resistors) are then connected to the Drain on the MOSFET.

    You can then use the analogWrite() function to specify the "brightness" of the pin (via PWM), and fade it or whatever you want.

    Keep in mind, if you're running a long wire of these you might see some dropoff in brightness as it goes along. You could do it in a loop to help minimise this.

    Also, if you're running it anywhere hostile, that might pick up spikes or other nastyness, you could consider running the PWM through an optocoupler prior to the MOSFET, to protect the teensy.

    Anyway, you should be able to find some schematics/info by googling MOSFET PWM LED driver or something along those lines.

    - Peter
    Last edited by ploveday; 03-27-2013 at 12:17 AM.

  5. #5
    Thanks Peter!

    I'm not familiar with MOSFET, so I'm going to do some googling.

    Re: dropoff in brightness . . . there most certainly is. How would you suggest I do it in a loop? Sorry if that's an obvious question . . . like I said, I'm new.

    Thanks again!


  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    It's difficult to see how those resistor are connected. They look like they might be 220 ohms? Each looks like it's in series with a LED, but I can't quite tell for sure.

    First of all, you should test your LED strip by simply connecting it to +5 volts. I didn't want to write this earlier, since I had no idea if you were using resistors. I'm still a little uneasy giving you this advise without a good photo or schematic, but there are resistors. Just know that if you ever connect a LED directly to power without a resistor, it will likely be damaged.

    So, when you connect them all directly to 5 volt power (no Teensy involved), all the LEDs should light at equal brightness. You can use a voltmeter at both ends of the cable, to verify you have a consistent 5 volt power down the entire line. Going from 5.0 at the input to 4.9 or even 4.8 at the output is probably fine, but if you're ending up with only 3.5 at the end, then you know you've got a problem.

    Peter is right, you'll need a transistor, since a Teensy pin can not deliver that much power. Here's another message I wrote, showing how to use a TIP102 transistor to turn power on/off to a pump. Your LEDs are pretty much the same thing, except the diode isn't as critical since you don't have a magnetic field like motor would.

    Hopefully this helps?

  7. #7

    Thanks again for your help on this.

    Yes, the resistors are 220 ohms, in series. I've been connecting them to a 9v battery, and they are roughly equal. There is some dropoff in luminescence among the five LEDs in the string (versus if the LED is isolated/not in a string), but that was something I expected.

    I do have some transistors. What type would you suggest (is this the TIP102 you mentioned?)? And where would I physically attach it to? Teensy? The LED? Apologies if this is in the link you included (, I'm still trying to decipher it.

    As far as the Teensy, I didn't order pins with it, so the outputs are exposed. I suppose the LED strings will require soldering directly to the Teensy board?

  8. #8
    Just an update on my end. I picked up the TIP120 as well as a Mosfet IRF510 (the only one they had at Radio Shack). I'm currently in the process of researching means of physically incorporating into my circuit, since I've never used one before.

    I have a few Adafruit Perma-Proto boards, two of which I've set up 555 Timers on for a separate circuit. I hope to set up a third with the Teensy, if that's even necessary . . . I'm still not sure as the best way to build the Teensy circuit.

    Finally, I came across this code which I think will accomplish the effect I'm after:

    Any guidance on this as well as previous unresolved issues still welcome!

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    The IRF510 probably will not work. Those types of MOSFETs normally need a 10 or 12 volt driver.

    Here's a quick diagram that might help...

    Click image for larger version. 

Name:	TIP102.jpg 
Views:	491 
Size:	13.4 KB 
ID:	350

  10. #10

    Thanks for the drawing! It's helpful, but I'm still having a hard time visualizing what the finished circuit will look like once the teensy is integrated with all the components.

    As I've gradually acquired more knowledge, I'm wondering if it will be possible to do this on a relatively compact scale, or to save my Teensy for another project down the road (once it goes into this, it's bye-bye forever, until I buy another).

    Your wisdom (and awesome product) is appreciated!

  11. #11
    I've kept working at this and did my first attempt at plugging in the Teensy (up until now, I had been in the research phase). Apologies if this is all very rudimentary . . . as I mentioned, I'm still very new to all of this.

    As expected, it was blinking when plugged in. I followed the instructions to load the "blink fast" hex file (which I downloaded as a zip file from github, since it was downloading as a txt file through the Teensy site), but nothing changed on the Teensy. As suggested by the graphic in the Teensy software window, I pressed the button, which deactivated the blinking. Could this be the HalfKay file? The Teensy software indicated, as expected, that blink_fast.hex was running, 0% used.

    I then tried using the Arduino software and tried to activate the blink example under the Teensy menu there. Still no change.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    If you're using Teensy 3.0, you must use Arduino. Do not use the 2.0-only stuff (there's a notice at the top of the page about where to go for Teensy 3.0).

  13. #13
    Re: Arduino, sounds good. However, I tried Arduino to no avail. Is there a way to return the Teensy to factory settings?

Posting Permissions

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