Arduino connecting and disconnecting continuously while my code is running.

I am using Arduino Mega to control 4 selonoid valves, I am using Relay,NPN transistor and 24V power supply.

My arduino gnd connected to power supply gnd. And selonoid pins 8,7,6,5 to the transistor.

My code is working well and there is no any error. But while code is running there is always clasic usb connect and disconnect sound i hear.

Attached you can see the circuit i’m using this circuitx4.

What are the possible reasons maybe you have seen before?

Do you think it is safe if i just skip this problem.

Beucase i will use the system for 45.000 cycle test it means it will take about 240.000 seconds.And also i am a ME so it was hard for me to make the system work now i just dont want to change anything:)

Thank you for your time.

Maybe your 24 volt power supply is too much for the Mega? This is from the datasheet on the Mega 2560:

Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V