system monitor and relays

I have a mega with 16 relays attached. The relays that are on at the time I open serial monitor will reset (off then on again) is there any way to prevent this Thanks Rick

If you reset, you lose all the memory of which relays were on. How is it supposed to know?

If certain relays are supposed to always be on at startup, wire to the NC terminals and then swap the on/off logic in your code.

Avoid using the Arduino serial monitor. Other serial programs won't reset the Arduino on connection.

If that doesn't work, consider cutting the reset line between the USB chip and the MEGA2560. There may even be a solder jumper specifically for this purpose. This will mean that you have to manually hit the reset button when you upload new code. (Don't cut the wire to the button.)

Ok so when I start serial monitor thats like resetting the Arduino

The relays that are on at the time I open serial monitor will reset (off then on again) is there any way to prevent this

Once the program is loaded on the arduino, you can add a resistor or capacitor to the arduino to defeat the serial open/close reset. The below have been tried and work.

capacitor of 10 uF between the pins reset and gnd

100 ohm resistor between the reset pin and the +5v pin

Thanks for that advice
I take it I remove the capacitor or resistor if I want to update the arduino