4
\$\begingroup\$

I'm designing a smart socket using an ESP-32 and a mechanical relay that can drive 5A at 240VAC. Following typical relay driving circuits, I would like to use an optocoupler between the MCU and relay. The relay that I'm using is a Panasonic APAN3105 that operate at a low coil power of 110mW(5V@22mA) based on the datasheet.

Typical relay current driver circuit use an optocoupler connected to a transistor which then drives the relay. Since I'm using low coil power relay, can I drive the relay directly from the optocoupler that is within the max collector current? Are there any downsides to this method?

schematic

simulate this circuit – Schematic created using CircuitLab

I have not selected the optocoupler yet but have narrowed down to a few which have generally the same properties (If = 20mA, Ic = 50mA)(EL817S(B)(TU)-F, PC817X2CSP9F, TLP785(GB-TP6,F(C)

What is the best way to drive a relay?

\$\endgroup\$
10
  • 2
    \$\begingroup\$ Why wouldn't you just drive the relay directly? Through a transistor if necessary? The relay already has galvanic isolation. The optocoupler is at best, redundant if the 5V coil supply is isolated from your MCU supply, and at worst pointless if it's not isolated. It's not that it won't work, it's just that it's a waste of an optocoupler and makes things more finicky with no benefit. \$\endgroup\$
    – DKNguyen
    Commented Oct 24, 2019 at 18:50
  • 1
    \$\begingroup\$ Optocouplers, in my experience, have inconsistent current gain for a given input; a circuit that works on the breadboard might not work the same way in production, since gain is different from part to part. Like DKNguyen, I'd like to know why you'd want to daisy chain isolation barriers. \$\endgroup\$
    – Bort
    Commented Oct 24, 2019 at 18:53
  • \$\begingroup\$ It also takes much more current from the MCU to drive the LED in the optocoupler than it is to drive a transistor. \$\endgroup\$
    – DKNguyen
    Commented Oct 24, 2019 at 18:57
  • \$\begingroup\$ Max, you may also want to consider using a MOC30xx series opto triac with an AC coil relay (uses the same AC to operate the coil that you are using to power the load) instead of using a 5 VDC coil relay. You don't necessarily have to use your 5 V rail and sometimes its nicer to power the coil from mains rather than further load down your 5 VDC rail. Just another thought, given that you obviously have access to mains AC. \$\endgroup\$
    – jonk
    Commented Oct 24, 2019 at 21:02
  • \$\begingroup\$ @DKNguyen I have 3 power rails on my board which are AC, 5VDC and 3.3VDC. The MCU is powered by the 3.3V. The reason why I'm using the optocoupler is due some articles I read online that claims that there are small chances that the relay can cause spark arcs especially in terms of relay failure which can jump into the coil. So an optocoupler can protect the MCU completely. Is this true? \$\endgroup\$
    – Max
    Commented Oct 24, 2019 at 23:08

4 Answers 4

2
\$\begingroup\$

As well as maximum Collector current you also have to consider the Current Transfer Ratio (CTR), maximum LED current, and output drive capability of your MCU.

Fortunately the ESP-32 has a hefty 40mA output at maximum drive strength, which might be needed because standard optocouplers typically have a minimum CTR of only 50%. To ensure low Collector-Emitter saturation voltage the optocoupler LED current should also be much higher than (eg. double) IC / CTR.

The PC817XN for example has 50% minimum CTR and 50mA Absolute Maximium LED current. That leaves no room for increasing drive current to keep the transistor in saturation. As CTR has a wide tolerance of 50-600% you might get away with it on a prototype, but not in production.

For reliability you probably want to keep the LED current below 25mA, and then you want a minimum CTR of about 200%. Therefore you should use the PC817X3 (rank mark C) or PC817X4 (rank mark D).

\$\endgroup\$
4
\$\begingroup\$

Are there any downsides to this method?

For most Relay/optoisolator combinations, this won't work because many relays need a current that is larger than the 50mA sinking current provided by most optoisolators. Using the optoisolator to drive another NPN works well without much addtional cost.

enter image description here
Source: https://howtomechatronics.com/tutorials/arduino/control-high-voltage-devices-arduino-relay-tutorial/

\$\endgroup\$
2
  • \$\begingroup\$ The coil resistance for the OP's linked relay is 227 ohms. It has a nominal current of 20mA. The question wasn't about most relays, it was about a specific relay. \$\endgroup\$ Commented Oct 24, 2019 at 19:25
  • \$\begingroup\$ Then do it they way the OP suggested, they already have that option, I was showing the other option \$\endgroup\$
    – Voltage Spike
    Commented Oct 24, 2019 at 19:27
1
\$\begingroup\$

Yes, as long as the relay coil current is less than the maximum collector current of the optocoupler then this should work.

In general, you want to make sure that you can get enough current through the LED from the microcontroller (taking into account the CTR of the coupler) but I expect you are well within that limit. Also, make sure that the maximum emitter voltage is greater than the coil voltage, but at 5V that should also be pretty easy.

\$\endgroup\$
0
\$\begingroup\$

You are looking a PUSH-PULL driver but some time isn't very cheap.

Ways i know (i tested) :

  1. FOD8342 work without any other component(work on 3MHz output).
  2. TC4421/4422 with an cheap optocoupler(about 1.5 MHz).
  3. UDN2981 need trigger resistors and cheap optocoupler(a few KHz)

A tip : Never use an uC (microcontroller without isolation(power source + IO systems))

I hope it helps someone, best regards!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Incorrect, this does not need a push pull driver. \$\endgroup\$ Commented Sep 13, 2020 at 12:17
  • \$\begingroup\$ @ChrisStratton yes , dont need, just add transistor for this ! \$\endgroup\$
    – dsgdfg
    Commented Sep 27, 2020 at 23:05

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.