How can an optocoupler be used in order to accept a voltage range for example between 3-50 volt to a digital input pin of 3 volt like on the Raspberry?

What would a typical circuit look like in order to drive the optocoupler? Would a simple voltage divider be good enough or is there other more robust ways?

  • 1
    \$\begingroup\$ It can't. Optocouplers use infra-red LEDs which require 1.2 to 1.4 V to turn on. You will also have to allow some voltage drop across the current limiting circuit. Explain what you are trying to do and we may have other ideas for you. \$\endgroup\$
    – Transistor
    May 31, 2019 at 6:43
  • \$\begingroup\$ @Transistor my goal is to have the input isolated and handle 1-50 volt \$\endgroup\$ May 31, 2019 at 6:55
  • \$\begingroup\$ 1 volt won't be enough to turn on the optocoupler (unless you also have some other power source besides the signal, and condition the signal, which is what I'd recommend). If you shrink the range to 3-50V then it's definitely possible. \$\endgroup\$
    – anrieff
    May 31, 2019 at 6:55
  • \$\begingroup\$ @anrieff ok changed to 3 volts. It will be ok! \$\endgroup\$ May 31, 2019 at 7:03
  • 1
    \$\begingroup\$ @www: "My goal is to have the input isolated and handle 1-50 volt." I got that from the title. What is the real problem you are trying to solve? What is your 1 - 50 V input signal? Is there power available on the input side? \$\endgroup\$
    – Transistor
    May 31, 2019 at 7:07

1 Answer 1


A large voltage range can be accommodated by using Vin to drive a constant current source.

Voltages below the minimum forward voltage of the optocoupler's IR diode could be accommodated by using a boost converter to up-convert the lower voltages - but this is best avoided unless the very low voltages are essential.

Here is a conceptual circuit diagram - which would work as is in most cases.
Component values can be adjusted to suit.
Vin is taken to be 3V to "more".
How high "more" is depends on the power rating of R2 and the voltage rating of Q2 and R2.

When voltage is applied Q2 is turned on by R2.
Current in R1 rised until Q1 is turned on when R1 drops about .6V.
Q1 now clamps the base of Q2 at a level that maintains its turn on voltage.
Current drawn I= V/R = 0.6V/R1 , which here =
0.6/100 = 6 mA (approximately).
This current can be changed by changing R1 to suit the optocoupler requirements.

Lower optocoupler currents ease the dissipation requirements discussed below.
Deep-ending on your source a low Iin may be essential.

At 3V in, V_Q2_b = Vb1_Q1 + Vbe_Q2 ~= 1.2V.
So V across R2 ~= 3Vin - 1.2V = 1.8V.
Ib_Q2 = Vr2/R2 = 1.8/10000 ~= 0.02 mA
To support the required 6 mA in this case Beta_Q2 must be IC_Q2/Ib_Q2 = 6 mA / 0.02 mA = 300. R2 can be made smaller to increase I_R2 and so reduce the required beta of Q2.

I specified a BC337-40 for Q2 as they are low cost, widely available and have guaranteed beta of 250 - 630 and typically 400.
At Vin of 3V operation is marginal at beta = 250 and reducing R to say 6k* would be wise.

BC337 data sheet.

The BC337 is rated at Vceo of 50V so is marginal at 50V (but probably OK - but ...). A surface mount version with identical specifications is available (except for dissipation).


simulate this circuit – Schematic created using CircuitLab

At Vin = 50V, dissipation in R2 = V^2/R = 2500/10k = 1/4 W.
Using at least a 0.5W part is indicated and 1W "won't hurt". If R2 is reduced power consumption should be checked.

Q2 max dissipation ~= Iopto x Von = 6 mA x 50C = 300 mW.
C337 TO92 package has a thermal resistance Rtja = 200 C/w.
At 300 mW temperature rise is 200 x 0.3 60C which is "not nice" but OK.

If you really want good operation across the maximum possible range something like the (almost magical) Diodes Inc ZXTN25100DG at under $US1 in 1''s ex Digikey, will do the job with ease. This is in a SOT223 surface mount package but is easily used on strip board or as a through hole part with mounting pins. Beta, dissipation and operating voltage are higher than for the BC337. What's not to like - apart from the still reasonable price?

Also look at the SMD only SOT23 insanely high dissipation rating ZXTN25100DFH - but the ZXTN25100DG is much nicer to use.

  • \$\begingroup\$ Thanks for this great reply including explanasion of the circuit. I will take some time to grasp this. A first question I have is that I am used to optocouplers having two sides. I guess you have just left out the part of it that will receive the light and open/close. Correct? \$\endgroup\$ Jun 1, 2019 at 18:37
  • \$\begingroup\$ @www.jensolsson.se Yes - I just showed the input side of the optocoupler \$\endgroup\$
    – Russell McMahon
    Jun 2, 2019 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.