Go Down

### Topic: I/O between arduinos with opto coupling. Sample schematic  (Read 5543 times)previous topic - next topic

#### raschemmel

#15
##### May 18, 2016, 11:21 amLast Edit: May 18, 2016, 11:24 am by raschemmel
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
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### Wawa

#16
##### May 18, 2016, 01:32 pmLast Edit: May 19, 2016, 12:06 pm by Wawa
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..

#### jeffez

#17
##### May 19, 2016, 05:41 am
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?

#### raschemmel

#18
##### May 19, 2016, 06:04 am
Collector saturation @ I(f)= 10 mA (R = 380 ohms)
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### jeffez

#19
##### May 31, 2016, 05:03 am
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?

#### raschemmel

#20
##### May 31, 2016, 05:29 am
Quote
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.
What protocol is that ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### jeffez

#21
##### May 31, 2016, 11:27 am
What protocol is that ?
Writing an analogue value on a pwm output pin then at the other end using pulseIn() to read the duty cycle and determine the value that was sent. I searched around and haven't found if there's a name for that kind of protocol other than the pwm.

#### raschemmel

#22
##### May 31, 2016, 03:11 pmLast Edit: May 31, 2016, 04:28 pm by raschemmel
How is that any more efficient that putting an (4.7 k/1 uF) RC LPF at the other end and reading it with analogRead ?

Actually, if you want to , there is no reason you can't use RS485 to send your data. I don't know why you chose to send PWM but you can still do that using RS485. Usually, data is sent using a protocol that involves a header, a packet and a checksum but that's beyond my level of S/W expertise. If I just needed to send an 8-bit value I would probably have to do it the same way you are, (because I don't know how to do it any other way , LOL).
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### jeffez

#23
##### Jun 01, 2016, 07:06 am
How is that any more efficient that putting an (4.7 k/1 uF) RC LPF at the other end and reading it with analogRead ?
It probably isn't. I actually had to look up what you meant by RC LPF which probably says allot. Being a software engineer i went for the solution that was electronically easier to understand but harder on the programming side of things. Somehow i got the impression that reading pwm has to be done manually in code on a digital pin. So maybe i should use an analogue pin read instead then?

Actually, if you want to , there is no reason you can't use RS485 to send your data. I don't know why you chose to send PWM but you can still do that using RS485. Usually, data is sent using a protocol that involves a header, a packet and a checksum but that's beyond my level of S/W expertise. If I just needed to send an 8-bit value I would probably have to do it the same way you are, (because I don't know how to do it any other way , LOL).
If it wasn't for the distance problem i would stick with pwm no worries, as i need to connect to four other arduinos. This way would mean everything fits on the one pcb with just a few optos and resistors.

If i only had to connect to one other arduino not four then RS485 could be better. Though i'm only wanting to send a single integer say 4-5 times an hour, so even then a line driver is probably a bit overkill.

If possible i'd prefer to use pwm but i'm not sure about the distance problem. The arduinos will be in a warehouse upto 100 meters from each other. I can write some error/interference tolerance into the code but for all i know pwm at those distances is practically impossible?

So i'm stuck between both solutions and currently not sure which way to go with! lol

#### Grumpy_Mike

#24
##### Jun 01, 2016, 09:07 am
Quote
If i only had to connect to one other arduino not four then RS485 could be better.
But RS485 is designed to be chained to multiple devices.

#### raschemmel

#25
##### Jun 01, 2016, 03:27 pm
Quote
But RS485 is designed to be chained to multiple devices.
While this is true, it is also true that an arduino can read analog or pwm on one pin and output it on another so really the distance is the deciding factor for which to use.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### Paul__B

#26
##### Jun 01, 2016, 06:41 pm
But RS485 is designed to be chained to multiple devices.
The OP specifies multiple devices.

Clearly, the proper way to perform this communication is with a serial protocol.  Any other will end in tears.

#### raschemmel

#27
##### Jun 01, 2016, 08:51 pm
Quote
Clearly, the proper way to perform this communication is with a serial protocol.  Any other will end in tears.
RS485 output at one end is exactly the same as the input at the other end. Is there any valid reason that input can't be serial ? (as far as I can tell it could be anything, including PWM).
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### jeffez

#28
##### Jun 03, 2016, 06:18 am
While this is true, it is also true that an arduino can read analog or pwm on one pin and output it on another so really the distance is the deciding factor for which to use.
Since RS485 is reliable at long distances i decided ill probably have to go with that.
I wasn't able to find any definitive info on whether pwm can run stable upto 100 meters. This distances may even need to be more than that.

#### raschemmel

#29
##### Jun 03, 2016, 07:05 amLast Edit: Jun 03, 2016, 07:05 am by raschemmel
Do you know what the range is for  RS485 ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Go Up