Optocoupler with floating wire - Page 1
Forum section: electronics / projects

author: crgarcia
author_rank: Regular Contributor
timestamp: June 19, 2022, 09:32:05 pm
content: I am making a PCB that inputs the output of a latching relay to detect if this one is on or off.To detect mains, I'm using this circuit:the AC optocoupler is an LDA210:datasheetThe problem is that sometimes it detects mains when there is no. I was thinking that this could be because the wire is "floating" when the relay is off.The optocouplers have an average CTR of 8500%, which it might make them too sensitive.What can I do to make this more stable when the relay is off?Would it help if I use larger resistors instead of the 300k ones?I guess I cannot pull-down the mains wire Full project url:https://github.com/crgarcia12/electronics-homeassistant-lightscontroll

author: Benta
author_rank: Super Contributor
timestamp: June 19, 2022, 09:49:12 pm
content: It would probably help more if you placed the 100n caps across the LEDs. And why use an obsolete coupler?What's the purpose of the 4u7 caps?

author: ejeffrey
author_rank: Super Contributor
timestamp: June 19, 2022, 09:55:15 pm
content: If that CTR is accurate that circuit will turn on with as little as 1-2 volts on the AC line, or with just a few microamps leakage current, easily picked up by capacitive coupling or AM radio reception. Increasing the 300k resistor wont necessarily help if the interference is capacitive coupling. Instead I would reduce the 10k resistor on the receiver to a smaller number and add a line to neutral capacitor on the input to shunt away high impedance capacitive coupling or antenna behavior make sure to use a line to neutral rated capacitor.

author: Benta
author_rank: Super Contributor
timestamp: June 19, 2022, 10:00:43 pm
content: Quote from: ejeffrey on June 19, 2022, 09:55:15 pmMinimum CTR is 300%, so it's not.

author: crgarcia
author_rank: Regular Contributor
timestamp: June 19, 2022, 11:43:09 pm
content: Quote from: Benta on June 19, 2022, 09:49:12 pmThe 4u7 are there to smooth the AC wave so that the ESP detects a constant LOW. In the other hand, I didn't really know how to properly calculate the right value of the caps, so I did some simulations with fastlab and it looked like that value would smooth the curve and "turn on" would be fast enough (simu link)Why would the caps in the LED size would be better? I tried to put as little things as possible in that side because it's mainsDid not know the opto was obsoleteQuote from: ejeffrey on June 19, 2022, 09:55:15 pmThe typical CTR is 8500, the minimum is 300. I tried the circuit with 1.1MΩ and still worked, so it's pretty high.Since I have those resistors, the V across the Led is 1.7V. Can I place the cap just before the optocoupler (after the resistors) and use a low V SMD cap? I don't have too much space left in that PCBWhat value of Capacitor could I use for that? Or any hints on how to calculate it?Thank you both!

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 21, 2022, 05:15:30 pm
content: With mains and other similar voltage, you always have to be careful about the voltage rating of your parts. With a 230Vac (rms) you already have 310V peak, and voltage surges can be much higher, and your parts have to be able to withstand those without failure. Old fashioned "regular" 1/4W THT resistor are normally limited to a working voltage somewhere between 100V and 200V, and SMT resistors (especially the smaller ones) are rated for even smaller voltages. So you have to use "special" resistors, or put multiple of them in series to get to be able to use them for high enough voltages.If the minimum CTR of your opto is 300, and the typical is 8500, then what do you design for?For how many of your products do you find it acceptable to fail after they have been put on the pcb, put into an enclosure and shipped to customers? (That is quite something different then a single prototype "working" on your bench.Opto couplers also do not age well, and the CTR is expected to get lower over time.Your optocoupler has a 3pF capacitance, and this could be a path for erroneous measurements.Once you use proper resistors on the primary side (those are safety critical) you can put a simple low voltage capacitor directly over the optocoupler LEDs (These limit the capacitor voltage to about 1V anyway). Short peaks may go right by your big electrolytics, and ceramic capacitors are much better at filtering high frequency stuff.Alternatively, maybe you can do some filtering in software, quite similar to debouncing mechanical switches, but you can start by measuring (ether with an oscilloscope and/or with your ESP32 itself) what sort of durations you get for the pulse widths.

author: crgarcia
author_rank: Regular Contributor
timestamp: June 22, 2022, 05:31:29 am
content: Exactly as you say Doctorandus_PNow I have the device for 4 days working in my bench and it has no issues at all. Even when this is something I am not going to sell or ship, and just use at home, I would really like to make it safe and reliableIn terms of safety, I am using first a 80mA fuse and then two 1W 2512 series resistorsRMCF2512FT150K (datasheet). They are rated for 200V/400V peak (the max I could find)I tried to calculate for 300% and with a margin:It seems there is consensus that to give stability, I need a capacitor at the led side:How can I calculate the Farad of the capacitor that I need?Are there other things beside Voltage and Farad that I need to take into consideration?Thank you!