Electronic – Driving relay directly from optocoupler, what is best

drivermechanicalopto-isolatorrelay

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?

Best Answer

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).