Arduino Mega fail-safe external resettable timer reset

I have an Arduino Mega 2560 that reads temperature and humidity in my home and then turns on or off fans and air conditioning. All works well although occasionally a spurious character or voltage spike or dip seems to send the Arduino into no man's land (locks up). A hard reset always fixes this.

I need a simple timer with the output pin connected to the Arduino reset and an Arduino digital output pin to reset the timer. The idea is that the timer provides a high level to the reset pin for about 30 seconds then outputs a low pulse of 500ms to the reset pin, thus resetting the arduino. In the meantime the arduino software will generate a reset (via a digital output) to the timer every 15 to 20 seconds causing the timer to reset to have the full 30 seconds again.

In normal operation, this circuit should never time out as the timer is being continually reset by the Arduino software. However, if the Arduino ever gets "lost" for any reason, the external timer will time out at 30 seconds and hardware reset the Arduino and life will continue as it should.

I have been looking at 555 timer circuits providing a monostable pulse of 30 seconds but it appears that once started, the pulse can't be reset or extended. I also need to be sure that the output of the timer circuit starts high and does not dip if the software reset trigger resets to extend the timer to its original 30 seconds.

I would welcome any suggestions or ideas for a simple circuit for this external timer which will always restart on power up.
Regards
Jamie

I believe the Mega processor has that function built in. Its called a WDT (for Watch Dog Timer). I'm not sure how to set it up on the mega but there are plenty of guides if you google them.

The WDT is a functionally separate timer on the processor that will reset your board if it is allowed to time out.

In your program setup you would set the watchdog to "timeout" in a specified period of time (from 15 ms to 8 seconds).

In your program you would "reset" the watchdog in every loop. If the loop fails to reset the WDT the WDT will timeout and reset your processor.

Basically this is what you described with the 555 timer.

Hope this helps.

Many thanks. will do some more research on wdt. How wonderful to have it built in.