2
\$\begingroup\$

enter image description here

Was look for a review to make sure I'm not doing something stupid. Looking at common relay modules on Amazon, it seems that something like this is going on. Would this work to control a relay from a 3.3V logic pin a la raspberry pi? I picked 4N25 and 2N2222 as components since I have them on hand.

The opto-coupler can't drive the relay directly because it would be too much current on the collector right? Assuming the relay wants something like 60-100 mA of current.

Here is an updated schematic using a different power supply for the relay. Not sure if the 1k base resistor is right though. enter image description here

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

The optoisolator is not doing much as shown since you've tied the grounds together. You could just drive the transistor base directly with something like a 240Ω resistor.

You should also have a diode across the relay coil. Something like a 1N4148 is fine.

If you have an galvanically isolated supply just for the relays then the isolator makes more sense.


Your edited schematic looks fine. Let's do some calculations of the resistor values using the Vishay 4N25 datasheet:

You have 220Ω and let's guess that the output will be typically about 3.1V when high and the LED voltage about 1.1V, so the LED current will be nominally about 9mA. The 4N25 has 20% minimum CTR so we can get as little as 1.8mA from the phototransistor, but typically 4.5mA (which will be limited by the base resistor).

A 5V 100mA relay will be more like a 20mA 24V relay. We would like base current of about 1/10 to 1/20 of that, or about 1-2mA, so the base drive should be just adequate

If you're doing a design that will operate over a wide temperature range and that should have a very long life you might want to use an optocoupler with a higher CTR and from a top-tier vendor to minimize LED aging such as a Sharp or Toshiba PC817B or C.

Base resistor could be something like 3.9kΩ or 4.7kΩ.

Vishay does not specify the maximum high temperature dark current, but at 25°C it's 50nA maximum (5nA typical), leading to a maximum collector current of maybe 10uA and typically perhaps 1uA. That will double about every 10°C so if you anticipate high temperature operation then an additional base-emitter resistor of perhaps 5-10kΩ will help deal with that leakage. If the top end of your ambient temperature range is higher than about 50-60°C you might want to make additional adjustments. In particular, using a better optoisolator (higher minimum CTR) will allow more margin.

\$\endgroup\$
2
  • \$\begingroup\$ So if I decide to use a galvanically separated 24v power supply and a 24v relay then the configuration makes sense? \$\endgroup\$
    – Dave Fol
    Mar 31 at 5:16
  • \$\begingroup\$ See edit. To get the maximum benefit from the optoisolator, keep the layout on the relay side well separated from the raspberry Pi side, just as you would if there were mains voltage across the optoisolator. \$\endgroup\$ Mar 31 at 12:44

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.