# Using optocoupler for 220V signal

Hello.

I am currently in the process of having an arduino switch a well pump on and off.
I already built a standalone ATMega168 board for this, and wrote the code.

Here is a description of the situation:
I have a water well, a pump, and a pressure vat. The pressure vat has a gauge that sends 220V signals.
There is one signal wire (L) for low pressure, and one signal wire (H) for high pressure.

What I need to do is when wire L has 220V on it, I need to turn on the pump. When wire H has 220V, I need to turn off the pump.
Now this turning on and off is easily achieved with a relay.
The troubling part is the 220V AC signal.

What I want to do, is halfwave rectify the 220V AC signal and use a capacitor to ‘smooth’ out the signal and put that into an optocoupler. (I have a few LTV817’s around).
That way I can use the optocoupler to send a 5V signal to the ATMega when wire L or H is having 220V on it.

I have been looking around on the web and there is lots of different info around and some solutions look even more half assed than the other, and I have a healthy respect for 220V and would prefer not to have Einstein’s hairstyle. Also the load of (mis)information out there quite confused me.

So what I need to know is, how do I make that LTV817 optocoupler ‘detect’ 220V AC in a safe way?

From what I figure, I can halfwave rectify the AC with a diode and use a 0.25W resistor of, pff, 100K in the circuit.
I realize that this will lead to a ‘flashing’ output on the other side of the optocoupler, but I can smooth that with a capacitor.

I drew a little thing with Fritzing and I wonder if this is the way to go? Anyone got any tips before I go get another hairdo tomorrow?

I probably know less that you about the details, but I always thought low voltage and high voltage circuits needed to be separated by a 1/2" at a minimum on circuit boards....

That 100k would have to be at least 0.5W, I think it would run cooler to use a 68nF 400V self-healing capacitor in series with a 2k2 fusable resistor. The resistor prevents any chance of the opto coupler exploding and shorting out across the isolation barrier (it burns out first), should the capacitor fail.

The other option is to connect the wires directly (well almost) to the microcontroller. “WAIT!” I hear you cry… won’t that destroy it? Well, yes, that is where the almost comes in. Stick a 1M resistor in series and you wont.

Here is an Atmel app note on the subject:
http://www.atmel.com/images/doc2508.pdf

Essentially what you get is a 5V square wave at mains frequency if there is a voltage, and nothing if there isn’t.

Alternatively, use the optocouplers for added safety. Something like the attached circuit will probably work (one copy for each signal). The output would not be quite a high or low as the voltage in is a sinusoid so you would get a square wave out so the added R-C circuit would correct this.

[quote author=Tom Carpenter link=topic=260824.msg1841715#msg1841715 date=1407971368] Alternatively, use the optocouplers for added safety. Something like the attached circuit will probably work (one copy for each signal). The output would not be quite a high or low as the voltage in is a sinusoid so you would get a square wave out so the added R-C circuit would correct this. [/quote] The 0.1µF series capacitor and 1k resistor to limit inrush current is the way to go.

What you want is one of these optocouplers which incorporate the two LEDs back-to-back.

You do not need the capacitor to "smooth" the output. Just write the program to poll a few times over each power cycle. If your code does not provide for this - then it is done wrong!

Well, as is obvious, there are more roads that lead to Rome. There again are a lot of different opinions on how this should be done.

I calculated that I needed to change the 100k resistor to a 200k (or use 2x100k in serial) and it worked just fine. Plugged it into a wallsocket, and nothing exploded. Measured everything and it's in perfect working order.

Thanks everyone for your input!

[quote author=Tom Carpenter link=topic=260824.msg1841715#msg1841715 date=1407971368] The other option is to connect the wires directly (well almost) to the microcontroller. "WAIT!" I hear you cry... won't that destroy it? Well, yes, that is where the almost comes in. Stick a 1M resistor in series and you wont.

[/quote]

Under no circumstances follow this advice. Its could lead to loss of life and property.