Go Down

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

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

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

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

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

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

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

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

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

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?

http://www.benripley.com/diy/arduino/three-ways-to-read-a-pwm-signal-with-arduino/

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

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

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

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

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

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

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