Mains Relay (240v) activating arduino Pin

Hi,

What I am tring to do is tell when a mains line has been made live. So I thought I would get a 240v coil relay (A Beta BLY5-2C (http://www.beta.com.tw/product_detail.php?serial=25)) and tap in to the mains line, then when it's on the relay would trigger a digital pin on the Arduino.

My question is:

Do I need to do anything else on the Arduino side other than connect 5v to one termial of the relay and a Digital Pin to the other?

Thanks for you help.

Matt.

Yes. You will need to “tie” the input pin to the opposite signal to that which the relay switches it to. If you connect the relay between 5V and the pin, you will need to “tie” the pin to 0V through a resistor, so that when the relay isn’t being powered the pin is held at 0V by the resistor. When the relay turns on, the resistance between the pin and 5V is much less than the resistance between the pin and ground, and 5V is read by the pin.

A 10KΩ resistor is typical.

Hi Majenko,

Thanks for the info, that make sense. Do you think it's a good idea to include a diode across the relay terminals on the Arduino side also?

Matt.

No, you're switching low voltages.

Using a relay could certainly work, but is a cumbersome approach that no electronics engineer would choose. Here are 2 alternatives:

  1. Use an opto isolator (preferably one that accepts AC input such as http://www.farnell.com/datasheets/6555.pdf) with series resistors on the mains side, and enable the internal pullup resistor on the Arduino digital input. The signal received by the Arduino will be pulsed because or the zero crossings, but you can allow for that in the code.

  2. Wrap a few turns of wire around the outside of the switched mains cable, and connect that wire to an Arduino input pin which is connected to ground through a resistor of about 1M. The pin will pick up the mains signal through capacitive coupling.

dc42: The pin will pick up the mains signal through capacitive coupling.

... I think you'll find that's inductive, not capacitative.

No, it's definitely capacitive - the capacitance between the live wire in the cable and the wire wrapped around the cable couples the signal to the Arduino input pin. To use inductive coupling, you would need to split out either the live or neutral wire from the cable and feed it through a current transformer (which could be a home-made one wound on a ferrite toroid).

oh yeah, you're quite right. I always think induction whenever there is a coil of wire involved... I mis-read and thought one end of the coil was connected to ground, but it's not, is it? It's floating. Which yes makes it a capacitor.

Hi Both,

Thank you so much for your time and help.

As this is a temporary bit of work that I am doing just for monitoring before I implement my own solution that will control the mains I will use the relay. I will however keep in mind about the opto isolator as that looks like a much nicer solution (Did some reading up on them after your comment dc42, thanks).

Matt.

Hi dc42,

Thanks for your suggestion about capacitve coupling.

Using an Arduino oscilloscpe, I can see a random signal mainly fed from mains noise in the air (230V 50 Hz here) as soon as I put 10 cm of wire into A0.
Now I built a voltage divider with 2 of my largest resistors ( 1.2M ) between 5V and GND on a breadboard, and got a clear 2.5V flat line.
Touching the center point with a finger, produces a signal of about 1.5 … 3.5 Volts (with similar 50Hz noise pattern).

Now I tried your “poor man’s coupler” trick, but got at max a voltage level varying about 0.2V only around that center line. ( 2.3 … 2.7 V)
I can confirm it’s capacitive (not inductive), as it’s independent of a current flowing through the line, but a difference between switched on and off is “clearly” visible.

It works slightly better if wound around the separated live line only, but that might be due to the smaller distance ?

Applying my scenario to an LTSpice simulation, I guess there’s not more than about 2pF of coupling capacity.
Any hint on how to improve the effect ? ( using 30 cm aluminium foil (household tin foil) instead of “a few turns of wire” ? )

Or is digital much more sensitive than an ADC channel, where a capacitor needs to be charged?

Spending two 1.2M resistors for a safe but useless “mains detector” lets me think about adding a zener (or a diode and about 30k resistor) , connect the two 1.2M resistors directly to the mains lines and have an unsafe but strong mains detector (turning 325V into 4V pulses @0.1 mApeak) as well.
Sure, optocoupler is the better way to go.

But not unscrewing mains installations, and using “jelly beans” parts is a good thing. If it worked, it were great.

michael_x: Hi dc42,

Thanks for your suggestion about capacitve coupling.

Using an Arduino oscilloscpe, I can see a random signal mainly fed from mains noise in the air (230V 50 Hz here) as soon as I put 10 cm of wire into A0. Now I built a voltage divider with 2 of my largest resistors ( 1.2M ) between 5V and GND on a breadboard, and got a clear 2.5V flat line. Touching the center point with a finger, produces a signal of about 1.5 .. 3.5 Volts (with similar 50Hz noise pattern).

Now I tried your "poor man's coupler" trick, but got at max a voltage level varying about 0.2V only around that center line. ( 2.3 .. 2.7 V) I can confirm it's capacitive (not inductive), as it's independent of a current flowing through the line, but a difference between switched on and off is "clearly" visible.

It works slightly better if wound around the separated live line only, but that might be due to the smaller distance ?

Applying my scenario to an LTSpice simulation, I guess there's not more than about 2pF of coupling capacity. Any hint on how to improve the effect ? ( using 30 cm aluminium foil (household tin foil) instead of "a few turns of wire" ? )

Or is digital much more sensitive than an ADC channel, where a capacitor needs to be charged?

There is no need to use 2 resistors as a voltage divider, because the capacitance between the wire wrapped around the cable and the live wire works as the upper component in a voltage divider, and if the voltage should exceed 5V, the pin protection diode will deal with the small current flowing through the capacitance. All you need is a resistor to ground. The higher the resistor, the greater the sensitivity. If 1M doesn't provide sufficient sensitivity, use 4M7 or 10M, or wrap some more turns of wire around the mains cable. Yes, a digital pin will be more sensitive than an analog pin.

PS - did your Arduino oscilloscope also have a resistor between the input and ground? If so, that would have reduced the signal.

I just tried it, using 10 turns of fairly thick insulated wire wrapped tightly around a 3-core 240V mains cable, connected to a digital pin. It works reliably with a 22M pulldown resistor, but not with a 4M7 pulldown resistor.

Thanks for your test. So your limit seems around 10M and my 1.2M is too small. ( Don’t have bigger ones available )

My idea of tin foil makes nice results, too:
I wrapped a normal 2wires cable 25 cm with foil and embedded my “sensor” wire in the wrap.

DigitalRead() finds 1000 to 2000 state changes per second, when mains is switched on and 0 when switched off.
That’s far more than what a clean 50 Hz sinus wave should produce, but it’s very significant.

I used the AnalogRead test to get a better idea what’s going on:
To move zero up to 2.5V I have those two 1.2M resistors to GND and 5V supplying the sensor data in the middle:

Sure it’s possible to let the built in diodes eat signals outside 0-5 Volts, as there are no currents involved.