Resistor for optocoupler

Hello all,

I have some optocouplers:

I want to connect these straight from the arduino (mega). Would a resistor be needed to limit the current?


yes. the side connected to the Arduino is pretty much just an LED, so it needs a resistor. (Moreover, it's a tiny little infrared LED inside a big insulating package, so Vf is lower, thermal dissipation is lower, and directly connecting to an output pin is even more likely to cause damage to the pin and/or the LED than would be the case with a visible-light LED.)

A lot more fragile, A whole lot.. I know from very bitter experience. I had some red LED's connected across the inputs to a couple of opti couplers (both with separate resistors) and I found one time when there was a massive transient that popped some breakers, that some sensing stuff had been damaged and it took quite a long time to find it as the LED's worked.... But the Opto's didn't, both of them. I thought I was so clever, including the led's, without them and I would have measured the led first..


Here is a visual.


I don't quite know If I would wire the transistor quite that way but there is no reason why it wouldn't work and as far as more gain, by the time the red LED turns on fully or at about 4V the opto will be fully on so the transistor probably isn't needed for extra 'gain'. The circuit should drive an Arduino input just fine.


To save component costs and space:
You can probably just ground pin 4 (the output emitter) and wire pin 3 (the collector output) directly to a arduino input pin, then just enable the internal pull-up resistor for the input pin. Then reading a LOW means opto in on and reading a HIGH means opto is off.

You can save another resistor by wiring the visible led (if being used) in series with the opto’s input and adjust the resistor size downward accordingly.


Would a resistor be needed to limit the current?

Look to the datasheet. Most of the times, people try to set them to work at the highest current transfer ratio, or flatest current transfer ratio. Typically that's 1 - 10ma.