Arduino hangs on switching AC 24V with opto-isolated relay board! why?

Hello everybody!

I am using an Arduino Mega with Ethernet shield and a 8CH opto-isolated relay module… for controlling my irrigation system, with 24V AC solenoid valves.

I am having trouble, every now and then (happens randomly) the arduino hangs when switching the relay…
I know it sounds something like EMF or so… but how can that happen if I use opto isolation??

Plus, I notice something even stranger…on a particular relay, if the relay is ON, the arduino sometimes hangs after 2-3 minutes. It should water the grass for 10 minutes, on that zone, and after 2 or 3 min, it stops, and the MCU resets. I have watchdog timer implemented in arduino, thats why the board reboots, otherwise it hangs until i unplug it from the power source.

Please tell me, how can I avoid this irritaiting problem? If it is something that I must add, capacitor, resisor, diode… anything. What and where to put?

The other solution is to switch to SSR relays, where is no EMF or any interference. But until then, It must be a solution with the classic relays, otherwise I wil definitely leave them for any project from now on, and switch to SSR.

I found a picture, made by @dlloyd, wich is exactly how I wired the relay board for use opto-isolation.

Any help would be apreciated.
Thank you very much!

Adrian.

p5UBRLY.png

Did you use snubber circuits on the relays.

How is the Mega powered.
Leo…

p5UBRLY.png
Twelve volt relays? 24 VAC valves?

This is all to do with how you have arranged the wiring, exactly what you have used for power supplies and what other parts and controls you have not described. A number of clear pictures illustrating everything in full daylight would be the absolute minimum to start with.

If the program hangs at a certain time with no relay actuation, then you obviously have a code problem. First suspect is the use of (capital) "String" coding.

Twelve volt relays? 24 VAC valves?

I assume the relay coils take 12v DC, and the relays can switch up to 240v AC.

Seeing the code would be nice.

Steve

Is the arduino running off a power supply that uses the SAME AC as the 24V AC VALVES ?

Noise spikes on solenoid shutoff can feedback through the AC through the ac/dc power supply and into the arduino , causing it to reset.

You can confirm this by temporarily powering the arduino from a 9Vdc battery plugged into the external dc barreljack and running the system to see what happens when the solenoids turn on and off.

Hello guys!

thanks to everyone for your time and interest for my problem. I will reply to all your questions one by one.

Wawa:
Did you use snubber circuits on the relays.

How is the Mega powered.
Leo..

No, I am not using snubber, to be honest I am not sure what that is...:slight_smile: I am using just the 8ch relay board.
Mega is powered from a separate DC 5V supply. For the relay board, I have another 5V supply. (Relay board works at 5, not at 12 as is described in the picture I posted. My mistake I did not mention that, anyways I think it doesent matter.)

steve1001:
Twelve volt relays? 24 VAC valves?

I assume the relay coils take 12v DC, and the relays can switch up to 240v AC.

Seeing the code would be nice.

Steve

No, 5V relay board, 24VAC for solenoids, 24V AC is present at the relay contacts. Solenoid work with 24V AC and power consumption around 150-200mA. Not much!
The code i will show you in the next post, althought its preety big, because it does other stuff too, other than just switching relays.

Paul__B:
p5UBRLY.png
Twelve volt relays? 24 VAC valves?

This is all to do with how you have arranged the wiring, exactly what you have used for power supplies and what other parts and controls you have not described. A number of clear pictures illustrating everything in full daylight would be the absolute minimum to start with.

If the program hangs at a certain time with no relay actuation, then you obviously have a code problem. First suspect is the use of (capital) "String" coding.

I will send pictures. I am sure it is not the code, since it happens only when relays switches on/off, and not all the time.

raschemmel:
Is the arduino running off a power supply that uses the SAME AC as the 24V AC VALVES ?

Noise spikes on solenoid shutoff can feedback through the AC through the ac/dc power supply and into the arduino , causing it to reset.

You can confirm this by temporarily powering the arduino from a 9Vdc battery plugged into the external dc barreljack and running the system to see what happens when the solenoids turn on and off.

The arduino power supply is from the same power socket, (wall socket) as the 24V AC transformer is...
Well, here things are different. The 24V AC transformer is controlled also by one relay, so the transformer is not active all the time, just when needed for irrigation. Arduino turns on two relays when it needs watering. Not at the same time, I guess its a second delay there. Once it activates the relay corresponding to irigation zone that needs water, and then after a second or half a second it powers up another relay to give power to the 24V AC transformer.

Interesting thing to test it. From a clean 9V battery. I don't know how long can last such a battery, since the mega with eth shield draws a lot of current ( I guess around 300mA)...But it's worth testing it.

As I promised, the pictures with the hardware.
I don’t boast at all, and I am not happy with the wiring in the relay box. There are many wires there leftovers from previous setup. Did not have time to rearange them, please ignore that, if you can :slight_smile:

From Mega to relay board, I used aprox 50cm of 8 wires shielded cable.
In the other box, I have an LCD, and behind him, is the mega (in the same box), an RTC clock, and a small PCB for interconectivity of sensors, LCD, RTC, with the Mega.
The main reason I choose this setup, was to prevent EMF or spikes or whatever may happen, (thats why I isolate the Mega from the relay board, not to be in the same box…) but seems like I failed… Strange things still happens…

As i mention the code is big, since it does many things.
It fills the water tank from the well, stops when the tank is full, stops when is no water in well, stop the pump if tank gets empty…etc.
Besides that, mega sends all this data to a mysql server.
From the server it gets the sensor data. By this value, the mega knows how much time to water, or not to water at all it rains that day… it’s complex. but if you ask for it… I have no problem sharing :slight_smile:

Thanks.

irrigation-and-tank-controller.ino (22 KB)

If you have to run the Mega from an AC/DC power supply plugged into an outlet SHARED by the 24V solenoids (not the preferred way to go), then your only recourse is to start adding 0.01, 0.1 and 100uF to 1000uF capacitors throughout the box .

Are you in the USA ? (Is it 50Hz AC or 60Hz AC ?)

The capacitive reactance of the caps is : Xc = 1/(2pif*C)

C =
1e-08
Xc =
318309.886183791

C =
1e-07

f = 50
C = 1000/1e6
Xc = 1/(2pif*C)

Xc =
31830.9886183791
C =
1e-06
Xc =
3183.09886183791
C =
0.0001
Xc =
31.8309886183791
C =
0.001
Xc =
3.18309886183791
f =
1000
C =
1.0000e-07
Xc =
1.5915e+03
f =
1000
C =
1.0000e-08
Xc =
1.5915e+04

f =
10000
C =
1.0000e-07
Xc =
159.1549
f =
100000
C =
1.0000e-07
Xc =
15.9155

Eventually, if you add enough of these caps, the 24Vac spikes will be absorbed by the caps and will
no longer effect the processor.

If it were my equipment and I wanted to make sure it was stable , I would just add 3300uF across the
5V power (Vcc) of the Arduino and ten 0.1uf, ten 0.01uF, and ten 0.001uF caps, scattered at all four corners
of the box. Another approach is to use a TRIPLE layer of power filtering by using an AC/DC 12V power supply that feeds a 12Vdc to 7.5V DC to DC converter that feeds the Mega External DC power barreljack
and then put caps on the 12Vdc power, the 7.5Vdc power and the 5Vdc power (1000uF on each) in addition to 5 of each of the three smaller caps (in bold) on each Voltage line.

If you have no formal electronics training you are probably wondering how this is going to help.
As you can see the calculations for the de-coupling caps, (AKA "BYPASS CAPS") is given as European
50hz.

Now , imagine a noise spike from a solenoid, having a frquency of 1000 Hz (instead of 50 Hz).
What will be the effect of the caps with that frequency ?
If you look at the different combinations of frequency and capacitance in the calculations, you can see that the higher the frequency the lower the reactance (in ohms ) of the caps and the larger the capacitance the lower the reactance at a given frequency. Since electromagnetic noise spikes are never consistently any one frequency, having a range of capacitance, covers a range of noise frequencies and
the more capacitance, the better, and you can never have TOO MUCH capacitance, so be generous with
the capacitors and the larger the better. Nobody can tell you exactly how many of what value will elliminate your problem but pretty much everyone will agree that the more different values of cap the better and you can't have too much capacitance.

raschemmel:
the 24Vac spikes will be absorbed by the caps and will no longer effect the processor.

There is ofcourse nothing to absorb is the spikes are not generated in the first place.
Snubber circuits across the solenoids are NOT optional.
Leo..

Snubber circuits across the solenoids are NOT optional.

RC SNUBBER CIRCUIT

I was aware of the use of snubbers to eliminate relay contact arcing but don't see how they apply to a solenoid that has no contacts.

Can you provide any math to support that ?

The OP is using conventional relays instead of SSRs, so it is logical to assume relay contact arcing upon solenoid switching via the relays. This arcing could very well feed back through the AC and I would agree with the statement that snubbers across the contacts of relays switching solenoids, are not an option, but if you hypothesize solenoids switched by SSRs, would you still be advocating snubbers across solenoids switched by SSRs that likely have no arcing ?

The 8-relay modules come with flyback diodes.

DC relay coils must have a diode across, to protect the transistor from the (hundreds of volts) kickback spike.
Can't use a diode for an AC driven coil, but there is still a kickback, depending on the phase of the AC.
Can use a resistor across the coil, and if the value is the same as the resistance of the coil then kickback voltage should be less than twice the AC drive voltage.
A capacitor in series with that resistor could reduce wasted power generated in that resistor, while still letting the fast kickback spike through.
There are also other options, like a voltage dependent resistor (VDR) or bi-directional TVS diode.
Parts values on the snubber circuit you linked to might not be ok for 24volt AC.
Leo..

raschemmel:
If you have to run the Mega from an AC/DC power supply plugged into an outlet SHARED by the 24V solenoids (not the preferred way to go), then your only recourse is to start adding 0.01, 0.1 and 100uF to 1000uF capacitors throughout the box .

Are you in the USA ? (Is it 50Hz AC or 60Hz AC ?)

No, I am in EU/Romania. 50Hz here.

I think you did not understand me. The Mega is powered by a 5V/1A power supply (similar to phone chargers). The transformer for solenoids wich gives 24V AC to solenoids is a separate power supply, but they are in the same wall socket. So I don't know what you mean by shared :)) They are like 2 separate things plugged in the wall socket.

Where should I put capacitor. The 5V line for the mega has a 16V 2200uf capacitor on the expansion board. Where should I solder new caps? could you draw a few lines for me?
Thanks.

They are like 2 separate things plugged in the wall socket.

So, so what ? Do you actually think that 24V noise generated on one wall socket outlet WILL NOT affect something plugged into the OTHER socket on the SAME WALL PLATE ?

Just how much training do you have with electricity ?
Do you think the electrons circulating in the circuit plugged into the top socket of the wall plate are DIFFERENT electrons than the ones circulating in the BOTTOM socket of the SAME WALLPLATE ?

Please tell me you don't believe that.
Also, do you think that your 1A /5V power supply offers complete ISOLATION from the AC line ?

There is some filtering in the ac/dc power supply but it does not offer 100% isolation. For more money you could get one that did but it is easier just to add filter and decoupling caps.

Didn't you say that you were going to run a test of the Mega running off a 9Vdc PP3 battery to see if the unstable behavior goes away ?

Interesting thing to test it. From a clean 9V battery. I don't know how long can last such a battery, since the mega with eth shield draws a lot of current ( I guess around 300mA)...But it's worth testing it.

If you live in an apartment building and something gets into the water system to change the color of the water coming out of the faucet , are you going to go next door and ask your neighbor if you can borrow some clean water ?

Options: If you have access to the circuit breaker panel and are able to do some testing to see if there is another nearby outlet on a different breaker circuit, you can move the 24AC supply for the solenoids to a different breaker circuit and then it shouldn't affect the Mega.

I’ve draw a quick schematic of the connections.

Is there a question ? ( I know what you have. You didn't need to draw the schematic. It changes nothing)

See Reply #8

Didn't you say that you were going to run a test of the Mega running off a 9Vdc PP3 battery to see if the unstable behavior goes away ?

Interesting thing to test it. From a clean 9V battery. I don't know how long can last such a battery, since the mega with eth shield draws a lot of current ( I guess around 300mA)...But it's worth testing it.

I had exactly same problem for same application.
I added a snubber consisting of 100nf 400v cap + 100ohm res (in series) parallel to each solenoid valve.
Works magic.
Not sure optoisolators serve any useful purpose. Who would have a bunch of isolated power supplies?

raschemmel:
So, so what ? Do you actually think that 24V noise generated on one wall socket outlet WILL NOT affect something plugged into the OTHER socket on the SAME WALL PLATE ?

I have noticed it is an old thread but I wonder: do you really think a spike from a solenoid will get through the 24V transformer to the nearby socket, through switching power supply input filter, transformer, output filter, possibly long wires and Arduino onboard decoupling caps and still stay strong enough to consistently cause soft processor fault? There is so much inductance and capacitance on the way. I think there must be some other explanation. Such as a SW bug or interference with some other part of the system (i.e. unhandled I2C bus error).

raschemmel:
RC SNUBBER CIRCUIT

I was aware of the use of snubbers to eliminate relay contact arcing but don't see how they apply to a solenoid that has no contacts.

Can you provide any math to support that ?

Doesn't matter very much if the snubber is across the relay or across the switch contacts if
the supply is stiff... The snubber's job is to divert current flow somewhere to limit the voltage
increase due to the inductor - in other words it limits the peak value of dI/dt to something
manageable.

Having it across the switch allows AC to leak through at low power when the contacts are open,
having it across the load doesn't.

If you have an isolator switch having the snubber across the inductor means you only need one
snubber, rather than two.