1
\$\begingroup\$

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...

\$\endgroup\$
  • \$\begingroup\$ Why does your software deliberately restart itself from time to time? Deliberate self-restart is an uncommon thing in firmware design. \$\endgroup\$ – Nick Alexeev Nov 29 '14 at 4:49
  • \$\begingroup\$ Maybe use a latching serial-in parallel-out shift register with SPI? \$\endgroup\$ – copper.hat Nov 29 '14 at 5:10
  • 2
    \$\begingroup\$ Or use a latching relay. \$\endgroup\$ – Wouter van Ooijen Nov 29 '14 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 Dec 1 '14 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 Dec 1 '14 at 0:31
1
\$\begingroup\$

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.

schematic

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.

\$\endgroup\$
0
\$\begingroup\$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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