# Reading an optocoupler datasheet and calculating the resistors for its input/output

This is a continuation from this question (sort of)

I want to replace the relays from an existing circuit with optocouplers and had trouble how to read the optocoupler datasheets as well as understanding how they operate. I think I understand a little now, but still consider myself quite newbish in the topic.

I changed the optocoupler from the previous question, since I've found that it's probably easier to start with a more widespread component (4N25 or 4N27).

If I understand opto-couplers a bit better I might switch to a more fitting opto-coupler for my appliance.

So, to start, here is the schematic with relays:

simulate this circuit – Schematic created using CircuitLab

Since optocouplers consist of LEDs an input protection resistor is necessary. Also there's a voltage drop from the transistor on the output.

For the Input Module the schematic is almost identical, since the voltage drop of the transistor is neglect-able on the module side. But for the Output Module I have trouble finding the right resistor so that the Passive ($$\ I_{passive} = 10mA \$$) / Active state ($$\ I_{active} = 20-30mA \$$) for the monitored output are still correct.

The output module has an internal resistor of 26K7 ohm and a MOSFET bypassing that resistor when active.

Here are my schematics with optocouplers:

simulate this circuit

I also don't really know how to calculate the resistor for the LED.

It seems to me like the output module can't be used with optocouplers, as the passive state is enough to activate the led / saturate the transistor.

Reading the datasheet, there's this figure, which tells me the 4N25 would become active from the passive state of the output module.

EDIT:

R2 on the output module is mandatory because it's a monitored output.

When the output is inactive, the internal 26K7 ohm resistors will limit the current to around 10mA (in series with 800 ohm). This 10mA basically tells the circuit that there's no wire-break.

Now, when the output is active, the internal resistor gets bypassed. With the bypass all I have is the 800 ohms, which needs a parallel resistor to limit the current on the LED.

But that's where I fail, since I don't know how to size R3 properly.

I feel like I'm getting this wrong.

A few comments about your assumptions and notes: 1) Your note states that 10mA must flow for broken wire detection. But using ohm's law and the voltage and resistance values you provided: $$I=\frac{V}{R} \rightarrow \frac{27.5V}{26.7kΩ}=.001A\rightarrow 1mA$$ Knowing this much lower "passive" value, make this a bit easier to design with. So now what you need to do is differentiate between 1mA and 20mA. Your method is one way to do this, and you can complete it with a zener diode:

simulate this circuit – Schematic created using CircuitLab

R3 is then calculated as follows: $$\frac{(27.5V-10V-1.3V)}{20mA}=810Ω$$

So in summary, R2 will provide a path for the 1mA sense current while D2 blocks the opto from turning on. When the mosfet activates and presents the full 27V to the output, then the zener will break over and conduct while R3 limits the current to 20mA through the opto's LED.

• Oh boy... I shouldn't look at circuits all day. You're right, it's 1mA.. I mixed it up with the 10mA required for the passive state of the input module. Geez. – HackXIt Aug 12 '19 at 20:28
• Zener diodes. The answer I've been secretly looking for. – HackXIt Aug 12 '19 at 20:36
• Why do you use the 1N4740A in your example and not 1N4749A, which has a nominal voltage of 24V? The resistor would be $\frac{27.5V-24V-1.3V}{20mA}=120Ω$ ... Also in your calculation you used 26.7V, which should be 27.5V instead. – HackXIt Aug 12 '19 at 21:17
• @HackXIt Good eye, I did the math correctly, but typed it in wrong. So the resistor value stays the same. You could use that value of zener if you want, just make sure you get the power ratings correct. 24V*10mA≈0.5W! A larger voltage zener will dissipate more of the power. The 10V zener will split the power more evenly between R3 and D2. – Aaron Aug 13 '19 at 1:11

R3 needs to be sized to turn the LED on when you apply voltage, but not burn it out (it is an LED)

With LED's (or any diode) its easiest to limit the current with a resistor like this:

Source: 4N25-X datasheet

The max current the diode can take is 60mA with a recommended value of 50mA. Since the voltage is 27.5V and the diode is a 1.3V drop, the resistor would need to drop 26.2V. So we use V/I=R, 26.2V/0.05A = 524Ω minimum for the resistor. (you don't need the 800Ω resistor to create a voltage drop, it will only burn up heat). Going with a lower current than 50mA for the LED current is probably a good idea (26.2V/0.03A = 870Ω)

This graph shows the relation for different forward currents of the LED of the transistor side of the device (the brighter the LED, the more forward current the transistor will get).

Source: 4N25-X datasheet

• I need the 800 Ohm for the 10mA on Pin(-) of the Output Module. The problem is that when the Output is activated, the 26K7 resistor that is in the output module internally gets bypassed, and so if I don't put a resistor before the LED it will burn through. But I also can't get rid of the 800 ohms, because then I would lose the 10mA of the inactive state, which are mandatory.. Sorry, I need to rephrase my question – HackXIt Aug 12 '19 at 19:37
• @HackXIt These devices are best used to switch things on and off, they are highly depended on temperature, if you try and maintain a current, it will vary with temperature. Maintaining a current is not a good idea. The LED should be on or off. – Voltage Spike Aug 12 '19 at 19:40
• Maybe what I'm trying to do is not even possible. Like, I can't use a monitored output to drive an optocoupler, because the "monitoring" will damage the LED over time? – HackXIt Aug 12 '19 at 20:14
• No, it won't. But you may not get the results you want. What are you doing with the GPIO on the otherside of the opto? Are you detecting high/low or do you plan on connecting it to an ADC? – Voltage Spike Aug 12 '19 at 20:24
• Simply detecting High and Low. – HackXIt Aug 12 '19 at 20:34