Sometimes on reboot, relay switches position for a few seconds

Sometimes on reboot, relay switches position for a few seconds

Is there a way to prevent this?

I am using Arduino Yum and the relay is connected directly to output pin, 5v and gnd.

Maybe with some circuitry?



When you reset the Arduino processor, all of the output pins become inputs until your sketch starts to run and makes them outputs again. For a short time during startup, whatever is connected to an output pin will have a floating input. The normal way to handle this is to add external pull-up or pull-down so that even with the output floating, the device is held in a "safe" state (usually off.) if the processor is reset while the output is on, the pull-up/down resistor will turn the output off, until the code is running again and turns it on.

If you don't want this to happen, you could add some sort of external latch that remembers the last set state, and holds that value while the processor is restarting. But that brings up its own potential issues: what will be the state of that latch when the circuit first powers up and until the Arduino sets it up the first time? Or what will it do when the board is powered up and there is no sketch programmed? You want to make sure it won't do something incorrect on power up. The usual way to handle that is to gave a power up reset pulse, often using an R/C delay like the one used on the processor's reset pin.