Opto-isolator for the Teensy 3.0

Status
Not open for further replies.

MichaelMeissner

Senior Member+
I'm a programmer who is approaching embedded microprocessors without a strong electronics background, so I may be missing something obvious.

I have this little project (firing my steampunk camera from a telegraph key) working on an Arduino, and I thought I would try to move it to the Teensy. In the middle of the project are two opto-isolators to go between the Arduino and the camera. On the Arduino, I used 4N26JP opto-isolators. I moved the opto-isolators to the breadboard I have the Teensy 3.0 in and hooked it up with a simple program that did both blink LED 13 and turned the opto-isolator and and then turning both off. I hooked a LED powered externally and first tested the setup with the Arduino and it worked fine. Then I loaded the same program on the Teensy and it didn't work. Now, I got the opto-isolator from a generic pack at my local electronics store, and I recall looking for an opto-isolator that was triggered by 5 volts.

So, I went back to the store and bought a NTE3041 opto-isolator, but that doesn't seem to work. I thought I was being safe by getting one where the VF voltage was 1.5V max and the VR was 6V max, thinking anything between 1.5 volts and 6 volts was safe. So I likely misread the package, and want something triggered by 3.3 volts. What parameters should I be looking for in an opto-isolator that would work with the Teensy? Ideally, I would would like a single one that will work with both the Arduino and the Teensy, but that may be harder to find. Are there known opto-isolators that work with the Teensy?

I should mention, that is is possible that I wired the NTE3041 incorrectly, and I just need to better wire it up. I will try to do it again later. I need to solder up the test rig so I don't have to worry about wires coming up, etc.

Another solution that I've thought about is getting a voltage converter, such as this bi-directional converter offered by ladyada: https://www.adafruit.com/products/757

:confused:
 
Last edited:
The typical, basic opto-isolator is not a very low-power device. It has as input a simple unbuffered IR LED inside, and often requires at least 10 mA current drive. The Teensy 3.0 is rated for only 9 mA current drive from the GPIO pins. You can find opto parts that will work at lower current, eg. some will work at 6 mA. I don't know if that's your issue, but it's one possibility.

From looking at a LITE-ON version in the 4N26 part, you can use a lower current, but then the current transfer ratio really suffers. Look at Fig.4 "Current Transfer Ratio vs Forward Current" on page 8 of
http://optoelectronics.liteon.com/e...r.ashx?txtSpecNo=DS-70-99-0010&txtPartNo=4N25
 
Last edited:
The typical, basic opto-isolator is not a very low-power device. It has as input a simple unbuffered IR LED inside, and often requires at least 10 mA current drive. The Teensy 3.0 is rated for only 9 mA current drive from the GPIO pins. You can find opto parts that will work at lower current, eg. some will work at 6 mA. I don't know if that's your issue, but it's one possibility.
Thanks, it makes sense. I guess for now, I'll keep the Arduino for this task, and look at using the Teensy for other things. If anybody knows of places to get the lower current opto-isolators, it would be appreciated.
 
The opto input is just an IR LED. Like driving any LED, you need a resistor to limit the current. I didn't see any mention of resistors above, so the first question is if a resistor is being used in series with the opto's LED?

Usually IR LEDs have a forward voltage of approx 1.3 volts. Teensy 3.0 has 3.3 volt output, so approx 2 volts will be across the resistor. I'd recommend trying a 220 ohm resistor, which will set the current at approx 9 mA, which is the maximum recommended current for the pin.

Those lower current optocouplers are nice, but this same advise applies. You still need to choose the resistor wisely. If the value is too large, the current will be too low to light the LED up inside the optocoupler.
 
The opto input is just an IR LED. Like driving any LED, you need a resistor to limit the current. I didn't see any mention of resistors above, so the first question is if a resistor is being used in series with the opto's LED?
No, I wasn't using a resistor. It had just worked for the Arduino for the opto-isolators I had bought. I didn't recall seeing resistors in how-tos I had read about opto-isolators -- I suspect it is thee, and I just glossed over it. I have packs of resistors, and will look up a 220 ohm resistor. I do have problems being slightly color blind distinguishing between the brown and orange rings on the marking, but I can dig out the multimeter to be sure. Thanks.
 
Something I've found endlessly useful...keeping resistors in their shipping packaging...I can't memorize all that color crap, I just keep them seperated when I get them.

(I live 2 blocks from Mouser Electronics so I just keep them in the mouser bags)
 
Something I've found endlessly useful...keeping resistors in their shipping packaging...I can't memorize all that color crap, I just keep them seperated when I get them.

(I live 2 blocks from Mouser Electronics so I just keep them in the mouser bags)

Well in my original Arduino purchase, I purchased a 'kit', and the vendor just threw everything into a single plastic bag with no labels for any of the parts. Needless to say, I have not purchased anything from that vendor since then.

I then bought a bag of multiple resistors from another vendor as part of a larger purchase. This one did go to the trouble of having somebody write the omns on each strip of resistors, but unfortunately the handwriting is hard to read, and they didn't use a permanent marker so it wasn't much of an improvement.

If I can't find the 220 omn's, I will buy some in retail packaging, and keep them labeled like you do.
 
Mea culpa -- it turns out I was using a dead 4N26JP. I had bought 6 of them, and 2 are dead. I happened to use the 2 dead units on the Teensy and it didn't work. When I took one of the 4N26JP's from my working Arduino setup, it worked like a champ on the Teensy. I then verified that the other 3 4N26JP's were working fine. So, I need to make sure I throw away the dead units. Sorry about that.

I did hook up one of the working 4N26JP's with a 220 omh resistor between the pin on the Teensy and the anode pin and it didn't seem to work. So for now, I'm using it without the resistor.

Thanks for your help.
 
Your designs are up to you... it may be working fine now, but driving a LED with no series resistor is asking for trouble IMHO. The LED is a diode and will clamp the output to its forward voltage drop. A slight change in CPU voltage will possibly cause a large change in LED current, and may cause overstress on the CPU's output pin driver. I don't think running an output with voltage clamped to about 1.5 V is within the CPU's I/O specification.

If you drive from a more beefy source, it could also exceed the "absolute max" current of the LED itself leading to a dead optoisolator part.
 
Last edited:
With no resistors at all, either your opto-isolator or your teensy output will fry. Maybe not immediately, but be prepared.

I use some CNY74's with 220Ohm resistors, it draws less then 6mA
 
Last edited:
Electrically, it does not matter.

I usually prefer to put the resistor close to the Teensy's pin. Then if anything goes terribly wrong, the pin at least has the resistor between it and a short to ground or 5 volts or something worse. Often the resistor will limit the current enough to save the chip.
 
Electrically, it does not matter.

I usually prefer to put the resistor close to the Teensy's pin. Then if anything goes terribly wrong, the pin at least has the resistor between it and a short to ground or 5 volts or something worse. Often the resistor will limit the current enough to save the chip.

I never thought about it that way....
 
With no resistors at all, either your opto-isolator or your teensy output will fry. Maybe not immediately, but be prepared.

I use some CNY74's with 220Ohm resistors, it draws less then 6mA
I just wanted to confirm that I just got the CNY74-2 optocoupler in the mail today, and I hooked it up with 220 Ohm resistors between the pins on the Teensy and the optocoupler, and it works great. Thanks for your help.
 
you can go for 330 Ohm for extra safety (I measured mine again with 220 on a Teensy3 and it was a bit over the recommended 9mA rating). I use it with an arduino Mini Pro to drive a DSLR shutter on the other end and served me well for many month now. I use isolated resistor networks (on ebay) to gain space on my thru-hole designs, but regular resistor are just fine of course.
 
you can go for 330 Ohm for extra safety (I measured mine again with 220 on a Teensy3 and it was a bit over the recommended 9mA rating). I use it with an arduino Mini Pro to drive a DSLR shutter on the other end and served me well for many month now. I use isolated resistor networks (on ebay) to gain space on my thru-hole designs, but regular resistor are just fine of course.
Yep, I was wondering particularly with LED banks whether there was a better way to have banks of multiple resistors than individual components. I'll see if I can source some locally. Thanks again.
 
in case you are worried about overdoing the loading on the Teensy output port, you can use two pins in parallel -- configure both as outputs, and have each individually drive the optocoupler via a 330 (for example) R. Then in software drive the ports sequentially:

Code:
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
{do stuff...}
digitalWrite(12, LOW);
digitalWrite(13, LOW);
there will be a brief interval when one is high and one is low, but since you have the resistors, no harm will occur (max. current is 5/(2*330) = 7.5 mA)

so (ASCII schematic !), you have:
Code:
PIN12---^v^v^v-----+-----|<|-----5V_supply
        330_ohms   |   {LED}
PIN13---^v^v^v-----+
 
Last edited:
in case you are worried about overdoing the loading on the Teensy output port, you can use two pins in parallel -- configure both as outputs, and have each individually drive the optocoupler via a 330 (for example) R. Then in software drive the ports sequentially:

I think I was unclear, my last comment was about resistors in general, using as an example a LCD bank where you might have 8 LCDs, and for each LCD you need a resistor. If you have a real small prototyping area, you might not have room for the normal resistors. I initially wasn't aware of resistor networks which can help in the cases where you are putting out multiple things that need the same resistors. I would hope that one resistor would be enough for one optocoupler, and that you wouldn't need two output pins.
 
One thing you should be aware of, with Opto isolators your (Maximum) ) Output current will depend on your Input current and the Current Transfer Ratio (CTR). If you look up the CTR (it may be termed something slightly different, but is often expressed as a percentage) in the Data Sheet it will show a figure, but you should look at the graphs to see how it varies for different input currents and output currents. Take the CNY74-2 you mentioned, at 6mA is has around 100% CTR and you feed say 6mA through the LED (inside the Opto), you will get 6mA x 100% = 6mA (maximum) output through your Output Transistor. If it was a 50% CTR, the it would give 6mA x 50% = 3mA out (maximum). A 4N32 also has a CTR around 100% if I recall correctly, as will lots of others.

The LED will have a limit on the current you can safely put through it, just as the Output transistor will, so don't exceed that. NEVER use the 'Absolute Maximum Ratings' specified, they are the point where the thing is cooking, always stick within the 'Electrical Ratings' or 'Operating Ratings' and stay well within those.
As somebody else alluded to here, it's very likely you've cooked the previous Optos by pumping too much current through them.

If you've set things up for say 6mA out and your device (eg. Camera trigger) needs 10mA to make it work, then it won't work or won't work reliably and you'd need to either add a transistor to the Output of the Opto as an amplifier, pump more current through the LED, or get an opto with a higher CTR and a suitable output rating for the Output Transistor inside the opto. There are also Optos with Darlington Outputs (two transistors in a high gain configuration) which can give very high CTR's and often have a relatively high Output current rating, but in most cases they're unnecessary for general purpose use.

I believe the Teensy3 is a 3.3V device (I may be wrong there, haven't looked at it much) and if so then you'd need a lower value resistor than you'd use with a Micro with a 5V output. eg. for a 5V Micro and an LED forward voltage drop of say 1.4V it would be 5V - 1.4V = 3.6V (across the resistor) / 6mA = 600 Ohm (so you'd use the nearest one, usually above that value), but for a 3.3V micro it would be 3.3-1.4V = 1.9V / 6mA = 317 Ohm, so you'd go for probably a 330R

Always use a meter to check your resistors, labels on the bag, even from a manufacturer, can be wrong and colours can get confused anyway, it's not uncommon to have browns looking like red, blue looking violet, yellow looking like brown and vice versa.

I attached the Datasheet, hopefully it sticks to this post.
 

Attachments

  • CNY74-2 Opto.pdf
    203.2 KB · Views: 381
Status
Not open for further replies.
Back
Top