I have a Arduino board, connected to a relay. When the digital pin on the board is set to HIGH, the relay closes. If the digital pin is LOW, the relay opens.

Now that from time to time, I will have to (software) restart the Arduino. The digital pin refresh, and therefore if the relay is closed, it will bounce open. Untill the Arduino board sends out a signal again.

Should I add a switch/ other electric components before the relay? Such that the signal could be "memorized"?

I have thought of using a time-delay relay. But once it is invoked, you'll have to wait until the delay time have pass to turn it off...

  • \$\begingroup\$ Why does your software deliberately restart itself from time to time? Deliberate self-restart is an uncommon thing in firmware design. \$\endgroup\$ Commented Nov 29, 2014 at 4:49
  • \$\begingroup\$ Maybe use a latching serial-in parallel-out shift register with SPI? \$\endgroup\$
    – copper.hat
    Commented Nov 29, 2014 at 5:10
  • 2
    \$\begingroup\$ Or use a latching relay. \$\endgroup\$ Commented Nov 29, 2014 at 8:11
  • \$\begingroup\$ Just a question on latching relay(never used one...), how long should I give the latching relay a signal?One second of signal or holding as long as possible until it goes out? I'm thinking if a "long" signal will cause flickering of the relay, thanks! \$\endgroup\$
    – MW_hk
    Commented Dec 1, 2014 at 0:30
  • \$\begingroup\$ @NickAlexeev I'm actually using a GSM sheild with Arduino, when it cannot connect to the server for a number of times, I will ask the Arduino to restart itself... Any other better solutions? :) \$\endgroup\$
    – MW_hk
    Commented Dec 1, 2014 at 0:31

2 Answers 2


I'm going to assume that the AVR controller on the Arduino board is similar to the Microchip PIC family in that the pins default to INPUT upon reset.

If that assumption is correct, all you need is a really simple sample-and-hold circuit for the relay driver. It also requires you to think about how you have your software structured.

First, I'll show the circuit. Then I'll talk about the software implications.


simulate this circuit – Schematic created using CircuitLab

Software is really easy.

1) Controller is just coming out of reset. Port pins are all currently set as Input.

2) Set port pin to desired level (Hi or Lo)

3) Change port pin(s) DDR to Output

Note that the above order is important if you want to avoid glitches. If you set the pin to Output first, then set the level, there can be a glitch.

Also note that the circuit introduces a delay of about 1 ms. I assume that is completely inconsequential if you are driving a relay.

You must choose a low-leakage capacitor for C1 but that's easy. Tantalum works pretty good.


Use the EEPROM library, save the state when it changes then on power up read the status back before setting the output. As long as this read/output is done first on power up then during a reboot the off period should be short enough not to bounce the relay. If there is any bounce you could try putting a capacitor across the relay coil to carry the relay over the reboot period.

  • 2
    \$\begingroup\$ If it's an Arduino there is that pesky 1 second delay waiting for the bootloader. \$\endgroup\$
    – tomnexus
    Commented Jan 29, 2015 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.