Reading a 120V AC powered relay state: problem with noise?

Hi,

I want to detect power failures in a greenhouse. So I came up with this simple idea. I bought a relay and it’s connected to the 120V AC power source. When there is a power failure, the relay will close the circuit and I want to detect it with one of the ARDUINO inputs. So I copied a simple circuit with a switch and a pull-down resistor. Instead of the switch, I connect the relay Normally Closed wires. This is working fine, sometimes(!), but then I loose Serial communication and if I add a LCD for example on the ARDUINO, garbage will display and the ARDUINO in general starts to do weird things after I switch the relay on/off a couple of times.

Now nothing is connected on that relay, so I guess the coil is causing some noise. Any simple ways to resolve that? Attached is my first fritzing diagram. This is actually my first post ever!

Thanks in advance for your help :slight_smile:

The relay are not correct connected, use COM and NO connections instead.

Try to filtering the signal with this circuit.
You also have to invert the signal in your code.

120VAC.jpg

alohapz:
You know the source of it. I know you from?

I do not understand, english is not my first language.

Pelle

Hard to say what the exact problem is, but you might be better served with an AC input opto-coupler like this one.

You need to have a capacitor (something like 0.1µF 440VAC working) in series with this also with a 1k resistor.

And it is safer and more reliable (may even be a significant part of the present problem) to have the switch/ relay/ optocoupler or whatever between the input and ground, not between input and Vcc.

A simple snubber circuit as Paul__B suggests should work great, and/or you could use an MOV.
I've used 130VAC rated MOVs with success and typically use this on 120VAC circuits. Don't confuse the 185V rating - this is DC.

Also, increasing the distance between the relay and Arduino would decrease (but not eliminate) any interference. Sheilding is another option to consider.

Do you have a de-bounce routine in your code? Can you post the code?

Thanks everyone, I tried a few of your suggestions with the material I had on hand. They made me realize that, maybe the relay just by being too close to the ARDUINO could cause interferences. I unplugged it from the board and just connecting/disconnecting it from the power source would cause the LCD display to start printing garbage. The closer to the board, the more I get garbage. Since my computer is connected on the same power bar and it is used to power the ARDUINO, maybe the interference comes from there. That garbage doesn't seem to affect the board, as the serial communication still take place and everything else works fine. So I reconnected it to try Pelle's circuit and it helps, but I still get the board to freeze from time to time, but a lot less often. All this made me try to use a shielded wire. So I took a shielded sound cable, and solder the shield to ground. Now the board doesn't freeze anymore. I'm just not sure if I should connect the other end of the shield to the ground of the electric line?

I'll give a try to the photocoupler, I didn't know they could work on AC, so that's cool. This will probably be more gentle on the power line and could fix my LCD garbage problem.

For the debouncing, I'm planning on making a function to do that, I'm just not there yet, but that's something I'll do very soon.

Its recommended to have a snubber on an AC relay coil to reduce arcing and noise, Your pullup resistor should be lower,
perhaps 470 ohms to reduce noise sensitivity and add 10nF to ground on the Arduino pin to further reduce sensitivity.

Point of note: The original radio transmitters were made by creating a spark across a gap. the relay can be good at creating a small version of this so in addition to creating a voltage transient, the relay can create an over the air spike that can be picked up at input pins.

sats:
I'll give a try to the photocoupler, I didn't know they could work on AC, so that's cool.

The device referenced does, yes.

dlloyd:
A simple snubber circuit as Paul__B suggests should work great, and/or you could use an MOV.

While the same pair of components can be used as a snubber, I was suggesting them as the way to supply current to the opto-isolator.

sats:
I'm just not sure if I should connect the other end of the shield to the ground of the electric line?

Absolutely not!

pwillard:
The original radio transmitters were made by creating a spark across a gap. the relay can be good at creating a small version of this so in addition to creating a voltage transient, the relay can create an over the air spike that can be picked up at input pins.

You sure of what you are saying? In this case, the relay contact is the actual thing connected to the input pin; it has nowhere near enough voltage on it to spark!

sats, when using a photocoupler in an AC circuit, the most important part is the AC resistor that drives the IR led. For a safe, long-lasting circuit, it needs a very high dielectric strength.

As per IEC 60950, The Basic test Voltage for Hipot test is the 2X (Operating Voltage) + 1000 V. To meet this requirement, the dielectric strength would need to be rated 1240V minimum.

This 15K resistor, although a bit pricey, can withstand 2000V.

EDIT:

3 of these 4.7K/2W resistors connected in series would give 1500V isolation and cost much less.

Sample circuit:

MarkT:
Its recommended to have a snubber on an AC relay coil to reduce arcing and noise, Your pullup resistor should be lower,
perhaps 470 ohms to reduce noise sensitivity and add 10nF to ground on the Arduino pin to further reduce sensitivity.

I think you meant to say AC relay contacts, not coil? I see no mechanism for a AC driven coil to create arcing and noise.

dlloyd:
sats, when using a photocoupler in an AC circuit, the most important part is the AC resistor that drives the IR led.

But in practice, a resistor dissipates an unnecessary amount of heat which is a particular problem if you wish the assembly to be compact, so the "trick" is to use as I described, a capacitor to limit the current. Note as I specified before, the capacitor must be (over-)rated for continuous reliable operation at the specified AC line voltage. Now in this case, the resistor has a totally different requirement; it serves two purposes. One is to limit the inrush current to the capacitor (not so much for the benefit of the capacitor, but for the opto-isolator) if power is applied to the circuit at a peak of the AC cycle. The other is that if the capacitor should fail and short out, the resistor will then burn out, strictly you wish it to behave as a "fusible resistor". Mind you if this happens, the opto-isolator will also be destroyed, so it is purely a safety matter and any mains circuitry should be in a suitably fireproof housing.

I have come to the supposition that all these LED light bulbs we are now using for energy efficiency, presumably do not use full switchmode power converters (expensive and potentially unreliable, thereby limiting the lifetime), but rather series capacitors, bridge rectifiers, a protective resistor as described, and as many LEDs as possible in a series chain. The rare "dimmable" ones would presumably be an exception.

retrolefty:
I think you meant to say AC relay contacts, not coil? I see no mechanism for a AC driven coil to create arcing and noise.

Yeah, that's what I was saying. :smiley:

But in practice, a resistor dissipates an unnecessary amount of heat which is a particular problem if you wish the assembly to be compact, so the "trick" is to use as I described, a capacitor to limit the current.

Ahh, I thought it was for the relay (missed that part of reply #10) - now that cools thing down - nice! +1

I think with these parts connected in series, if the cap fails, the resistor would warm up but easily handle the extra heat of about 1W.

Digi-Key

Digi-Key EDIT: capacitor has been re-sized from 1µF to 15µF

dlloyd:
I think with these parts connected in series, if the cap fails, the resistor would warm up but easily handle the extra heat of about 1W.

Hmm, let's see - you have specified a 1µF capacitor and a 15k resistor.

Reactance of the 1µF capacitor at 60 Hz, 1/2?fC is 2k6, which is negligible compared to the 15k resistor (not even worth calculating the vector sum), so you will be drawing about 7 mA at 110V which is probably OK to feed the optocoupler. This will indeed be dissipating 0.8W in the resistor, and that whether or not you include the capacitor.

If you had instead, a 330 ohm resistor, this would limit peak surge current to 400 mA and the capacitor would then be the limiting factor, giving a current of 42 mA - somewhat too much. A 0.22µF capacitor however would have a reactance of 12k limiting current to about 10 mA and a 1k (fusible) resistor (normally dissipating 0.1W) would limit surge current to 150mA which should be quite survivable. A short circuit on the capacitor would cause the resistor to dissipate 11 watts which should "fuse" a ¼W resistor in short order.

My thoughts for using the 15K/3W resistor would be that on its own, there would be about 8 mA current and 1W dissipated. The 3W type also has a higher working voltage rating than similar with lower power ratings.

Then adding a capacitor in series to reduce the rms current to about 4 mA, thereby reducing the resistor's power dissipation to around 1/4W. In this case, the capacitor and resistor would drop about 60VAC each - extending the life of both components.

If the components are put into a small enclosure that can handle 1W of heat, then it will get warm only if the capacitor fails, but the circuit will keep working. However, I didn't size the capacitor to achieve the 60VAC at the RC junction.

dlloyd:
Then adding a capacitor in series to reduce the rms current to about 4 mA, thereby reducing the resistor's power dissipation to around 1/4W. In this case, the capacitor and resistor would drop about 60VAC each - extending the life of both components.

Then you have quite forgotten your AC circuit theory. :smiley:

If you want to reduce the current in the resistor to a given value, which will always be the same current as through the optocoupler, then you size the resistor accordingly and forget the capacitor. For 4 mA, that would be about 27k.

Then you have quite forgotten your AC circuit theory.

…forgot to re-size the capacitor.

If you want to reduce the current in the resistor to a given value, which will always be the same current as through the optocoupler, then you size the resistor accordingly and forget the capacitor. For 4 mA, that would be about 27k.

What I did is size the resistor for required current and heat dissipation at 120V. On its own (R only or with failed capacitor) = 15K, 1W, 8mA.

Now R is locked in, so C is added to provide the benefits of dropping most of the working voltage, and reducing dissipated heat. I’ve resized C to 15µF. By looking at the circuit as a voltage divider, as described here
under Series Circuit, these are the calculations in Excel … VC = 98V, VR = 22V.

Therefore; Irms = V/R = 1.5mA, P = I2R = 0.03W
Current is reduced by 81%
Heat is reduced by over 95%

You seem to have forgotten your AC circuit theory.

You cannot have VC as 98V and VR as 22V adding up to 120V!

I do not know what formula you used for Excel, but you clearly omitted to include “j” as per the Wikipedia cite and the reactance of the capacitor has come out wrong as well.