Help with a timed relay circuit pleaaase!

Hi there,

I have an arduino project which needs to be left unattended for weeks on end and it occasionally crashes. Because I'm up against time constraints, the most reliable solution for me would be a circuit which can physically cut power to the arduino for around 10 seconds.

I'm imagining a relay controlling power to the arduino, which can be turned off by the arduino, while at the same time starting some sort of timer circuit that will flip the relay back and restore power to the after about 10 seconds.

Unfortunately I don't have the electronics know-how to do this!! Can anyone help? I think this would be of great use for other projects too.

Thanks!

The ATmega processor on which the Arduino is based has a built-in "watchdog timer" that can reset the Arduino if it doesn't go through loop() for a while:

http://tushev.org/articles/electronics/48-arduino-and-watchdog-timer

Thanks - I have looked into that but I wasn't sure if it would be as effective as a proper power cycle..

Also I have a wifly shield attached.

Does the latest bootloader support WDT?

Cheers

Works fine for me on the UNO down to at least 250 mSec. The worry was that if the bootloader takes too long the WDT may go off again be fore your code has a chance to turn off the WDT. Since it works at 250 mSec it should work at any longer interval. How often do you guarantee that your loop() runs, anyway?

In your setup() turn off WDT at the start of setup() and turn it on again at the end. Here is my test sketch:

#include <avr/wdt.h>

unsigned long ToggleDelay;

const int LEDpin = 13;

void toggle_led()
{
  digitalWrite(LEDpin, !digitalRead(LEDpin));
}

void setup()
{
  wdt_disable();  // Tell the watchdog to sleep
  pinMode(LEDpin, OUTPUT);
  ToggleDelay = 1;
  wdt_enable(WDTO_250MS);  // Tell the watchdog to reset if 1/4 second goes by without a pet
}

void loop()
{
  wdt_reset();   //  Pet the watchdog
  toggle_led();
  delay(ToggleDelay);  // When this delay gets up around 1/4 second the WDT should reset the Arduino
  ToggleDelay += 5;
}

The LED toggles on and off with the delay increasing by 5 mSec after each toggle. After about 25 blinks (50 toggles), when the delay has gotten over 250 mSec, the WDT detects the failure and resets the Arduino.