# How to select a good optocoupler for uart to 20 mA current loop converter?

I'm trying to make a circuit that converts UART signals to 20 mA current loop signals. I tried this circuit to switch the signals.

I am not much experienced in optocouplers I had just two types to test, TLP251 and 4N25. The below pictures show voltage of Node1 on oscilloscope. The input signal on TXD is a 20 KHz sqaure wave.

What is a good choice for optocoupler which is capable of transferring signals up to the 1M Baudrate of the uart?

This is what I got with 6N137.

The final Circuit in my mind would be something like below:

I need the logic to be the same not inverted which mean 5V on TXD makes 20 mA on current loop and 0V makes 0 mA.

• 6N137 and its derivatives. Aug 29, 2017 at 7:15
• @Marko Buršič I tried this opto but the result is not what I expected I edited my post with the picture of 6N137 output on 20KHz. Aug 29, 2017 at 8:02
• +1 That was fast. Do you have optocouplers lying everywhere? Aug 29, 2017 at 8:04
• @Marko Buršič haha. That was a chance I asked my friend nearby! Aug 29, 2017 at 8:07
• But the whole circuit is maybe wrong. What is the final goal, where do you expect 20mA? You will probably need a current source. Aug 29, 2017 at 8:09

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 – Schematic created using CircuitLab

Try this:

simulate this circuit

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

• I need this converter to connect to a PLC. The converter is going to be mounted on top of the PLC so the loop distance is not long. Sorry Marko I couldn't get the circuit so much. where does the TXD should be applied? What type of pnp should I use for Q1-4? What does that darlington pair do? Aug 29, 2017 at 10:47
• Which PLC? You need to TX and RX for use with PLC. Aug 29, 2017 at 11:44
• Siemens S5. It's just the TX part i will design RX later. Aug 29, 2017 at 13:19
• I have one working S5 converter DIY, I will search for the schematics. Aug 29, 2017 at 14:17
• Mine is dirty cheap using MAX232, 2 optos 4N25 one NPN transistor and two LEDs. I can't find the schematics. But is similar to this one: horter.de/doku/v24-tty_db.pdf Aug 29, 2017 at 15:01