Home Arduino watchdog timer 2 Electronics projects Julian Rogers Home

Arduino watchdog timer 1

If an Arduino is running continuously it may well crash at some point. The purpose of the watchdog timer is to detect this and reset the processor. As I understand it crashes may occur because of problematic software (under unforeseen circumstances the software might get trapped in an infinite loop, for example) or the program may overwrite something important in memory, not release space used for temporary variables etc. etc. The larger the program, the greater the danger something will go wrong as memory is finite.

The watchdog timer looks at pulses which are programmed to appear on a particular Arduino pin at regular intervals as the program works through its main loop. As long as the pulses appear, the watchdog is happy. If they have not appeared for a given time the timer clamps the reset pin to zero volts for a short time which will, hopefully, clear the problem. The Arduino has a built in watchdog timer which can be activated, apparently. However, instinctively I trust an independent hardware setup more to do this job.

From my own experience, sometimes it seems to me that problems develop in the software that don’t actually cause the program to crash. Variables get very unexpected values, for example, I assume because of memory getting overwritten. Here, the watchdog timer won’t help. However, it is possible to send a command to the Arduino to reset itself by connecting a pin to the reset via a transistor which inverts the startup state of pins which is zero volts. Without the transistor, the Arduino would be in a constant reset state. The circuit below caters for both these cases.

The watchdog is more complicated than some single 555 timer circuits that I have found on the Web. These seem to be directly coupled to an Arduino pin and, as far as I can see, may not work if the pin being monitored stays low when the program crashes. Or am I missing something? (Unfortunately, that’s happened more times than I would care to remember!)

Any way, my circuit is triggered by the transitions on pulses from the Arduino from 5 volts to zero volts (edge triggering).  The input is on the left of the circuit. The 0.01 microFarad capacitor and the 4.7k resistor and the diode turn the square wave pulses into negative going spikes which can trigger the timer on the left. The output goes high and would continue to be high for a period determined by the values of R1 and C1 (for the vales shown, this would be about 2 seconds) were it not for the input continuing to receive pulses from the Arduino. Each pulse acting through the two transistors effectively discharges C1 preventing the timer from timing out. (In normal operation, C1 would charge up through R1. When the voltage reached 2/3 supply voltage, the timer would time out and the output would drop to zero volts. As just described, as long as pulses are received, C1 will not reach the 2/3 supply voltage and so the output will remain high.)

However, if the pulses stop for more than about 2 seconds, the timer will time out and the output will go low. This will send a negative pulse to the second timer which will cause it to produce a 5 volt output for about 1/100 of a second. The transistor is turned on clamping the reset pin of the Arduino to zero volts for 1/100 of a second causing the computer to reset.

Further details of the operation of 555 (556 is the dual version) may be found in 555 Projects by EA Parr published by Babani (ISBN 0 85934 047 3). It’s an old book but very useful!

Circuit tested on bread board.

Next, building and testing the circuit.