I/O between arduinos with opto coupling. Sample schematic

Hi guys,
I'm looking at having some inputs and outputs between multiple arduinos. It will be across potentially lengthy distances and i'd be looking at using cat5 for cost and minimising interference.

I put together a schematic and wanted to see if it looks correct and if opto isolating is the best way to go. Basically when the pin outputs HIGH on one arduino, the other ones input pin goes to LOW.

This is part of an earlier project i did when i was starting out.
https://forum.arduino.cc/index.php?topic=362113.0

That circuit is fine as it goes. I would use 1K on the receiving end and 220R on the sending end.
However it might not solve any distance related problem, for that you need a differential driver and receiver. But that depends on the exact circumstances of your setup.

Grumpy_Mike:
That circuit is fine as it goes. I would use 1K on the receiving end and 220R on the sending end.
However it might not solve any distance related problem, for that you need a differential driver and receiver. But that depends on the exact circumstances of your setup.

Thanks, so i would want more current running from the arduino on the left given the long distance to ground?

Would a capacitor be worth using the help smooth out potential noise from the long distance?

You really need to define your meaning of " long distance "

For distances of up to 20 mtrs + then look at using a pair of MAX232 chips

RS-485

ARDUINO <=> ARDUINO RS485

playground.arduino.cc/Code/ModbusMaster

jeffez:
Thanks, so I would want more current running from the Arduino on the left given the long distance to ground?

No, the gain of the optocoupler is (usually) less than one, likely about 50%, so you need to feed more current into it than it can switch with the output transistor, thus the lesser resistance. It has no relationship to the distance.

Your diagram is however wrong - the optocoupler should be on the receiving side with the cable feeding the LED. The cable resistance will merely be part of, but almost certainly much less than the current limiting resistor for the LED.

jeffez:
Would a capacitor be worth using the help smooth out potential noise from the long distance?

Almost certainly not. Unless your signal is very slow, perhaps 10 baud.

Your diagram is however wrong - the optocoupler should be on the receiving side with the cable feeding the LED. The cable resistance will merely be part of, but almost certainly much less than the current limiting resistor for the LED.

I was wondering why that didn't look right.... ;D

ricky101:
You really need to define your meaning of " long distance "

For distances of up to 20 mtrs + then look at using a pair of MAX232 chips

In this case it might be upto 20 meters.
I currently have an opto relay board running 50 meters away over cat5 straight from the arduino drawing around 5ma per output pin.
Not sure how this works but using the same cable over a shorter distance with opto coupling between two arduinos is going to need more current and possibly even extra chips?

Paul__B:
No, the gain of the optocoupler is (usually) less than one, likely about 50%, so you need to feed more current into it than it can switch with the output transistor, thus the lesser resistance. It has no relationship to the distance.

Your diagram is however wrong - the optocoupler should be on the receiving side with the cable feeding the LED. The cable resistance will merely be part of, but almost certainly much less than the current limiting resistor for the LED.
Almost certainly not. Unless your signal is very slow, perhaps 10 baud.

Ah i didn't know which side to put the optocoupler! :smiley:
I put it on that side because i was told in another thread that its better to not apply voltage over a long distance wire.

Ive revised the diagram, does this look correct? I set resistor values from Grumpy_Mikes suggestion.


adult photo sharing

That's fine. All the resistors and wires are in the right places.

Note just by the way, that putting a HIGH to feed the LED will then switch on the transistor and pull the Arduino input LOW.

This is precisely as it should be, the safest way in case of short circuits. But your sketch logic will of course, have to expect this.

Grumpy_Mike:
That circuit is fine as it goes. I would use 1K on the receiving end and 220R on the sending end.
However it might not solve any distance related problem, for that you need a differential driver and receiver. But that depends on the exact circumstances of your setup.

An LED at the end of a long cable is differential, surely?

I have two opto relay boards connected to the same arduino, one about 50 meters away and the other about 10 meters. Both work well using cat5 and draw only around 5ma per channel. Infact i have two relay channels sharing the same output pin, which i plan to change but hey it still works! :D. My thinking is it should be possible to replicate this reliability using the same/similar circuit as what the relay board uses.

I haven't been able to find a schematic but by the look of the board there isn't any special driver on there?

http://www.ebay.com.au/itm/DC-12V-4-Channel-Relay-Module-Optocoupler-For-Arduino-PIC-ARM-AVR-DSP-HD23L-/131524714841?hash=item1e9f7be159:g:c-oAAOSwhwdVUbW-

Does the relay turn on with a LOW ?
It might be similar to this:

8-relay board.jpg

raschemmel:
Does the relay turn on with a LOW ?
It might be similar to this:

8-relay board.jpg

Thanks yeah it has Active LOW, i would say that must be an 8 channel version of my one. I'll have to find out what value R5 is plus the opto led resistance.
I'm starting to wonder if i have been wrong about the actual current draw from the arduino for each relay channel. I was told in another thread upto 4mA would be used but i may have misunderstood.

Post #29
https://forum.arduino.cc/index.php?topic=362113.15

LEDS don't have resistsnce. They are not "resistive" devices by nature because they are semiconfuctors. The fact that they conduct current does not mean they are resistive, just like the fact that somedthing that goes up in the air isn't necessarily an airplane.
Leds are NON-linear, because they are diodes, but the diode forward voltage drop is not a standard 0.7 V because they are special diodes with forward voltage in the 2.0 to 4.0 V range.
Their forward current is specified with their forward voltage:

ie;
"V(f) = 2.2 V @ 20 mA"
The current limiting resistor is calculated by
[Vin- V(f) ]/I(f) = (80V- 2.2 V)/0.020 A = 77.8 V,/ 0.020 A = 3890 ohms

jeffez:
I'll have to find out what value R5 is plus the opto led resistance.
I'm starting to wonder if i have been wrong about the actual current draw from the arduino for each relay channel. I was told in another thread upto 4mA would be used but i may have misunderstood.

R5 is 1k (102 printed on it). IR LED Vf is ~1.2volt. Indicator LED Vf is ~1.8volt.
So the Arduino has to sink (5 - 1.2 - 1.8 ) = 2volt / 1k = ~2mA.
Some boards have no indicator LED. Then current is ~3.8mA.
Leo..

So if i was to use a PS2501 Optocoupler

image free hosting

Going by the datasheet Vf is 1.15-1.4V
So i'm my schematic on the diode side
I = (5-1.15)/220 = 17ma

Is this correct? and if so is 17ma ideal or could i consider a higher resistance?

Collector saturation @ I(f)= 10 mA (R = 380 ohms)

Thanks this has helped allot and i have since done a new schematic for my project.

I'm now looking at using pwm as some changes in requirements means that simple HIGH/LOW readings wont be enough.

I'm thinking of having one input and one output channel between each arduino and using rj45 ports which would use two of the twisted pairs in the cat5 cable. All using the optocoupling like in the sample schematic with pwm on the output pins.

My questions are,
given the use of an optocoupler and the potentially lengthy distance should i consider setting the pwm output to a slow rate? From this document it says you can set them to output as low as 30Hz and 60Hz depending on which pin you use.
https://arduino-info.wikispaces.com/Arduino-PWM-Frequency

Also I'm considering to just instead use something like a the suggested RS485. How ever i need to connect to upto 4 other arduinos and with only one pair of serial i/o pins is this even possible?

I'd prefer to stick with the opto and pwm if possible to minimize the use of extra parts and keep everything on the one pcb. Is there an alternative way to deal with lengthy distances other than serial line drivers? Possibly some sort of pwm repeater?