How can i dedect i2c connection

Hello everyone.i made two sketch for two arduino about i2c connection.i had send data one arduino to second one and controlling second arduino relays. have two problem 1.when i lost i2c connection second arduino all relay run.i dont want can i fix? 2.when i restart arduino my relays first time run while 1 or two second.i write porta,low and pinmode (22,low) in void setup and etc.i tried a lot of things.but i cant block this stiuation.pls help me?

Please post your code as 1. could be a simple coding error where when I2C is not connected it defaults to relays on.

2 could be exactly the same problem as 1 but to be sure please post a schematic of your wiring and the make/model of relay your using. When the Arduino is reset there may be a few milliseconds (or longer with bootloader) where the relays are active before the pin direction and state are set, this could maybe be overcome by using the other contact pins on the relay (NO/NC) and reversing the logic of how the relay is energized.