dc42:
Try moving the Arduino further away from the solenoid and its wiring. In particular, that coil of red wire will create a varying magnetic field when the solenoid switches on or off, which will induce currents in anything close to it.Also connect a power diode in parallel with the solenoid (1N4001 will do), or a snubber network across the relay contacts.
Many thanks. Removing the coil of red wire and placing the Arduino further away indeed did the trick. Using the relay module from eBay, the serial port connection does not drop after the solenoid is deactivated. Then I switched back to my own custom-designed relay module. The serial port connection does not drop, but the text from Arduino stops after about 30 seconds of activating/deactivating the solenoid. The main difference between the relay module from eBay and my own relay module is the addition of a photo-coupler for the eBay one. Is the photo-coupler recommended for the relay module? It seems to isolate the "noise" better. Thanks a lot.