Questions about Relay Noise and Interrupts

I have an Arduino Mega R3 using a sainsmart relay board to control an AC actuated solenoid valve. The relay board has optical isolators. Pins 43, 45, 47 and 49 are connected channel 1, 2, 3 and 4. Arduino ground and arduino 5v are connected to ground and 5v on the relay board. Tested and this works fine.

I am also using an interrupt on pin 19 to count pulses. I have tested this to 400Hz and it works fine. I am triggering the interrupt on the rising edge of the pulse.

So the problem is this: When the arduino switches the valve, extra pulses get counted.

The relay board can be used so that an external supply can power the relays so the connection between the arduino and the relay board is only through the optical isolators. I tried this and the problem is still there.

I added the commands noInterrupts() and interrupts() before and after the commands to open or close the valve. I use a delay and found that the extra pulses are happening with in a second of switching the relay. In other words a delay of 1000ms almost eliminates the counting of extra pulses.

The number of pulses is pretty random, from less than ten to more than 50. It only occurs when power is on the AC side of the relay.

Ideally I would like to eliminate the noise and so I need some guidance on filtering I guess.

Any suggestions?
The relay board circuit:

Hello Blaise ,
What value resistor do you have in line with the optocoupler and the diode ?
The second thing I notice is that you don’t have true isolation with the power supply and the optocoupler…or I am not understanding your power supply feed to the optocoupler and the relay
What is the coil voltage of the relay ?
What supply voltage are you using to the arduino?
Have you metered the voltage to the arduino as the relay cuts in to see if there is a voltage drop or spike?
***Keep in mind I have limited schooling and I am mainly internet taught , but I have been working with electronics for many years .
I would likely have programmed the arduino output pin to be active high , then fed it through a 1 k resistor to the anode of the opto . The cathode of the opto then would be connected to arduino common or ground as some call it.
The aux power supply that feeds the relay ( if that is the way I am seeing it in your schematic) would then work exactly as you have it drawn.
BobbyD