Using optocoupler to level shift from 24 to 5 V - Page 1
Forum section: electronics / projects

author: Jakeka
author_rank: Newbie
timestamp: December 13, 2020, 01:32:05 am
content: Working on the following circuit to convert 4 24 V sensor outputs to 5 V for ArduinoUsing the ILQ615-3 because I have some on hand.A little confused about the output resistor, saw some articles that said leave it at 1.2K for best switching response, others said calculate it for output current (which I did in circuit attached).Since the Arduino only needs 5 mA I'm thinking I should go with the 1.2K for the sharper transitions but worried I'm missing something?R/James

author: ledtester
author_rank: Super Contributor
timestamp: December 13, 2020, 02:05:50 am
content: How fast is your 24V signal?If it is like a serial data signal (i.e. 9600 baud or more), have a look at this page for some design guidance:https://github.com/pepaslabs/Electronics/wiki/Designing-a-TTL-Serial-Opto-isolatorIf it is a slower speed signal you can get away with a higher value resistor.

author: Jakeka
author_rank: Newbie
timestamp: December 13, 2020, 02:56:00 am
content: Human activated interlock switch and ESTOP plus 2 proxy sensors.Nowhere near 104 uSec so I think I'm safe staying with the higher value.Thanks

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 13, 2020, 02:30:17 pm
content: Have a look at:https://html.duckduckgo.com/html?q=optocoupler+current+transfer+ratio

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 13, 2020, 02:34:48 pm
content: It's common ground and noninverting -- you can literally short across A to E and remove the opto. Set resistors for the right division ratio and it's good to go. Optionally, a 5V zener from GND to OUT, or a schottky (BAT54?) from OUT to +5V, protects the logic level in case the voltage is higher (or resistor ratio is lower) than expected, or due to ESD.Mind to include filtering, switches bounce over some ms and RF noise can have a similar effect. Best is a mix of analog and digital filtering; with the resistance shown here, a single filter capacitor will do well enough for that. Debouncing can be done digitally (say, with a sliding-average filter followed by a schmitt trigger).Tim

author: Jakeka
author_rank: Newbie
timestamp: December 13, 2020, 07:00:43 pm
content: The voltage divider was the original design but the Arduino max input voltage is 20V and if the zener fails and puts an open in the circuit I thought I could lose the Arduino. Although I don't know if I would lose all the inputs or just one. Eventually the number of inputs will expand once we have proof of concept so I want the isolation. Also if I decide to use the Arduino outputs I will need an optocoupler any way.After reviewing the link ledtester sent me, not worried about switching times, all the inputs are human triggered. Basically we are just adding remote automatic and manual local power cutoffs to a model railroad modular layout. So bouncing and RF noise are way to fast an event to bother me.Thanks for all the responses.

author: Zero999
author_rank: Super Contributor
timestamp: December 13, 2020, 07:29:58 pm
content: The Arduino's maximum input voltage is much less than 20V, but you don't need to worry. The MCU inputs have internal clamping diodes to the supply rails, so even if the zener diode fails, it will limit the voltage, so long as the resistor is a high enough value to limit the current to a safe level.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: December 13, 2020, 11:58:47 pm
content: 10 mA is excessive current, I think. This is about 0.2 W of power allocated on the resistor. You need to choose a resistor that can not heat up. Most optocouplers open perfectly at 5mA. I use 3.9 kOhm. I also think it is not necessary to load the output of the optocoupler 15mA. You have 10mA at the input, but you want to get 15mA at the output - not every optocoupler can transmit 150%.There is no point in such a load. I use the built-in pull-down resistor 10K on the STM. This works perfectly even in the event of interference.

author: Jakeka
author_rank: Newbie
timestamp: December 14, 2020, 01:31:55 am
content: The input and output currents are from a 5 V input test circuit in the VISHAY How to read a optocoupler datasheet Application Notes. Since they explain how to find the 5 V values I can use that knowledge to find the 24 VDC values (for the input circuit at least).For the output side it looks like the current is solely determined by the output resistor with the CTR value being the max/most efficient (If I understand everyone correctly).10 mA is what the optocoupler (ILQ615-3) is normalized at. At 10 mA the CTR is typically 150% according to the datasheet which is why I'm using 15 mA for the output calculations.Since I don't care about nano-second response times, if I use the 1.25K in one of the examples for the output resistor with VCC = 5V I would get 4 mA for the output current which should work for the input signals? The optocoupler is fine operating at a CTR of 25% instead of the listed 150%?I did find ILQ621 which is normalized at 5 mA with a typical CTR of 80% which would give me 4 mA. After I breadboard the circuit with the ILQ615-3 I'll give that a try.Also if Zero999 is correct about the clamping diodes and I don't have to worry about blowing the Arduino with 24V the voltage divider with the zener diode may still be an option.Digikey order is supposed to be here Tue until then I have to wait.

author: Zero999
author_rank: Super Contributor
timestamp: December 14, 2020, 09:28:26 am
content: If you don't need isolation, just use a potential divider. Choose high value resistors, to keep the current down.https://www.random-science-tools.com/electronics/divider.htm

author: S. Petrukhin
author_rank: Super Contributor
timestamp: December 14, 2020, 10:02:10 am
content: Quote from: Jakeka on December 14, 2020, 01:31:55 amThe CTR is the ability of the coupler, its power. No one requires you to use it at full load if there are no performance requirements.CTR >100 is more expensive and less common. If you look in the datasheet, you will see there "Interfacing with a CMOS logic is enhanced bythe guaranteed CTR at If = 1 mA." .. I.e. 1 mA on the led is enough for it to fully open, but the load on the transistor should not exceed If * CTR.Vishay optocoupler is good, but damn expensive. I use a Toshiba TLP290 - they are about 10 times cheaper and have two LEDs turned on counter-there is no need to protect against reverse polarity with an additional diode.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: December 14, 2020, 10:15:23 am
content: Direct connection via a voltage divider can be used, but it is less reliable, especially when connecting external lines with sensors.You need to use a TVS diode, but it still does not guarantee full protection, requires additional elements, and must be connected correctly.The optocoupler is better - it will definitely not pass high pulses and will not pass fast electrostatic pulses simply because the led does not have enough energy to emit light.