How to select a good optocoupler for uart to 20 mA current loop converter?
A simple current source with mirror. Google to find the calculation for correct resistance. The Q1 needs to conduct the N-th current of parallel transistors, where N is the number of mirror's parallel transistors.

Why current source? Because the current loop is to be used on long distance cables and low speed. The current source will compensate for the long cable resistance.







simulate this circuit &ndash; Schematic created using CircuitLab

Try this:







simulate this circuit

The S5 PLC already has two current sources for that purpose.