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...
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:

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.