I am working on a circuit to drive some water pumps. I intend to achieve a double galvanic isolation between the pumps and the CPU to ensure nothing bad will happen to the CPU.

Here is my schematic:

enter image description here

I am using a 4N35 optocoupler to achieve the first stage galvanic isolation between the 5V control signal and the relay driver circuit.

The relay driver circuit consists of a BC337 NPN BJT(Q1) a flyback diode (D1) and a resistor to the base of Q1 (R2).

As Q2 is intended to be used in saturation mode, I learned that Ic = VCC/RC, in this case VCC is the relay supply which is 5V and the coil resistance is 70Ω with 10% error, hence the worst case resistance should be 63Ω, knowing this Ic = 5/63 = 79.3mA.

Knowing Ic is now posible to solve for Ib, Ib = Ic/Beta, I am using the lowest HFE found on the BC337 datasheet, this value is 60.

enter image description here

Hence Ib >= 1.32 mA.

So now I know that I need at least 1.32 mA feeding through the base of Q1 for it to be properly saturated. The thing is that I don't know if R2 is needed on this circuit, because the optocoupler is already sourcing current.

If R2 is needed, how can I solve for its proper value?

  • \$\begingroup\$ I take it your relay does not provide reinforced isolation by itself? (Many cheap relays have trouble with this due to their pinout, but better relays have no problem with this, and are routinely used as the sole reinforced-isolation barrier between mains and a low-voltage system) \$\endgroup\$ Commented May 10, 2020 at 14:47

3 Answers 3


Your beta is actually closer to 100 for this use case (Ic = 100mA) The optocouplers CE junction voltage drop should be small, but lets say it drops 0.2V,

So 5V - 0.2V - 0.7V (transistor base) = 4.1V

79.3mA / Beta of 100 = 0.793mA

4.1V / 0.793mA = 1265 Ohm

So R2 should be about 1.2K

You do want to include R2, otherwise the transistor base looks like a diode to the 5V rail, and may damage both the transistor, the optocoupler and possibly your power supply by drawing too much current.

  • \$\begingroup\$ Great!, I was forgetting to consider the Vbe for Q1 also, So R2, should be at most 1.2k to enable Q1 to work in saturation mode, with this I mean that I could try a 1k resistor in R2 and it should not harm any component, am I right? \$\endgroup\$ Commented May 9, 2020 at 21:32
  • \$\begingroup\$ Correct, additionally saturating the optoocoupler should not be too hard either, voltage drop of about 1.7V, and a current transfer ratio of 100%, so it just needs about 0.8mA flowing though its led. \$\endgroup\$
    – Reroute
    Commented May 9, 2020 at 21:40
  • \$\begingroup\$ I think I understood it now, Thanks for your help! \$\endgroup\$ Commented May 9, 2020 at 21:41

Yes, you need R2 to limit the base current, and the current through the output transistor of the optocoupler. If it weren't there you would risk destroying one or the other of those components.

To calculate the needed value take the saturation voltage of your optocoupler output at your LED current, or look at the curves to see where Vce should be, then add the Vbe voltage of the BJT at your desired base current.

Subtract that value from the relay supply voltage and that's the voltage across R2. Size R2 to give your desired base current plus whatever safety margin you feel comfortable with, as long as it's below the max ratings of your parts.

  • \$\begingroup\$ So what happens if the optocoupler datasheet does not contain any data about Vce sat or something similar? , Can I assume Vce sat = 0.1 V? \$\endgroup\$ Commented May 9, 2020 at 21:36
  • \$\begingroup\$ Pick a reasonable number like .25 and give yourself plenty of margin. \$\endgroup\$
    – John D
    Commented May 10, 2020 at 3:13

R2 stops the base emitter of Q1 from simply shorting via diode to ground. It need only prevent the current from being so large something fries while stil being large enough to saturate Q1. You can assume the opto output NPN is also saturated in your calculation.

You know your minimum Ib required. You can look up the max current through opto or Q2 and pick a reasonable Ib in between then calculate how much excess voltage appears across R2 after \$V_{be.Q1}\$ is removed from the supply voltage.

  • \$\begingroup\$ Thanks!, I was missing the saturation state for the optocoupler, then R2 = 5/1.32mA , if so it should be smaller than 3.8kΩ right? \$\endgroup\$ Commented May 9, 2020 at 21:20
  • \$\begingroup\$ @ChecheRomo If you assume opto output satuation is zero. Dont forget to subtract Q1 base emitter voltage drop \$\endgroup\$
    – DKNguyen
    Commented May 9, 2020 at 21:25

Your Answer

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

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