Arduino hangs when working with relays and AC

I'm a begginer with Arduino and I'm trying to use an Arduino Mega with hydroponics. I'm using a 4 relay board with 5VDC relays to activate a pump and a lamp. Everything works fine until I connect things to ac, then the Arduino freezes after a while, so it's not a sketch problem. I used the freeMemory() function to see whether it was a memory issue or not but everything was fine, so I'm afraid it's some kind of electric issue, since things get ugly only if I connect ac. The connection diagram is quite simple, yet I can't see the problem (I believe my expertise is quite far from enough). Any help will be appreciated.

Hi, This is a common problem,

I suggest you read THIS PAGE.