Arduino setup runs when relay activates

Thank you for the explanation![quote="aarg, post:14, topic:918602, full:true"]

Not always. The code you posted produces a short LOW pulse before going HIGH. If you want an output to begin HIGH (for example as with an active LOW relay input that is pulled HIGH by an external pull up resistor), you have to do it in the reverse order, as the OP did. The output state written by digitalWrite is saved in a hardware latch that is independent of the output buffer stage.
[/quote]