Arduino Long Time Hardware Watchdog

There are times You need to be sure your application is always up and running, so You need a tool that resets the board if something goes wrong (crashes, infinite loops … and so on).
This kind of tool is called “Watchdog” and is a piece of independent hardware that monitors in some way the status of your application, detecting if something is going wrong.

Usually a watchdog is a timer that the application must periodically reinitialize to avoid the triggering of  system reset.

AVR microcontrollers have an embedded hardware watchdog, but requires to be enabled by programming a “fuse bit” and has limited timing capabilities: the timeout expires after some seconds, too short for some applications.
A strategy may be to reinitialize the timer in more than one place in the software, but this must be done carefully avoiding to introduce weakness in problems detection.

As I needed a long time watchdog I’ve build this simple one from some spare parts I had in my lab.

Watchdog Schematics

The schematics is very simple and is built around a LM555 timer configured for astable operation.

Let’s see how it works.
Remember that to reset the Arduino Board the RST line must be pulled Low for some time.
When the power is applied, Q is high and C1 starts charging through R1+R2; when the voltage on C1 reaches 2/3 of the power supply voltage the 555 pulls down the DIS line dicharging C1 through R2 until it reaches 1/3 of the power supply voltage. At this point the 555 stops discharging and the charge cycle starts again.
While C1 is discharging the Q line is pulled low resetting the Arduino board through D1.
As the RST line of the Arduino is involved in the firmware upload process, D1 prevents  forcing high the RST line all the time failing to enter the programming mode.
The Arduinio D0 line is used to reinitialize the timer. During normal operation the D0 line must be disconnected (Hi-Z state) to not interfere with the capacitor charging process, while must be pulled low to reinitialize the timer discharging C1 through R3 that limits to 9mA the current the Arduino must sink (R3 value can be lowered: the lower the value the shorter the pulse needed to discharge che capacitor).
Doing this requires a little software trick

void ResetWatchdog()
    pinMode(D0, OUTPUT); //The D0 line goes Low
    delay(200);          //Wait for capacitor discharge
    pinMode(D0, INPUT);  //The d0 line goes Hi-Z

To calculate timings You can use these formulas:

T_charge = 1.01 (R_1+R_2) C
T_discharge = 0.693 R_2 C

With values from the schematics:
T_charge = 1.01 (1,000,000+3,300) 0.000220 = 242.5 sec
T_discharge = 0.693 (1,000,000+3,300) 0.000220 = 0.294 sec

The magic constants 1.01 and 0.693 depends on the voltage the capacitor must have at the end of the charge or discharge process. If You’re interested in formulas take a look here.

Tcharge must be calculated with some margin to avoid unintentional resets

Watchdog Breadboard


Stay tuned, more Arduino stuff is on the way 🙂

This entry was posted in Arduino Projects, Hardware. Bookmark the permalink.

9 Responses to Arduino Long Time Hardware Watchdog

  1. Anthony Iannarelli says:

    Hello – would it be possible to use this as a plain reset circuit without the D0 rest for the watchdog? I was thinking about increasing the the R1 to 4 or 5 mega ohms to increase the time between resets. Would this work?


  2. Johannes says:


    I tried to understand your calculations, but I get in trouble with discharging: We discharge trough R_3, so we get
    U(t_discharge) = U_0 * exp(-t/(R_3*C) ).

    Let’s assume, C1 is “empty” at 1/10 U_0, so I get
    t_discharge < ln 10 * R_3 * C1 = 0,284 s.

    As far as I understand, the NE555 has nothing to do with discharging C1 if the watchdog is resetted by the Arduino in time. Is it, because there is a small current, following +5 – R1 – R2 – R3 – D0 (GND)? Or is there any mistake in my assumptions?

    And a second question: When C1 is at 2/3U_0, the NE555 resets the Arduino and discharges C1 to 1/3U_0. To charge again to 2/3U_0 less time is needed than in the initial charge process, isn't? ( t_initChage / (R*C) = ln2 -ln3 )


  3. Alessandro says:

    Is it possible to use this project for the Raspberry instead of Arduino ?


  4. Alessandro says:

    I have realized the watchdog but to work with Raspberry it is necessary to add another diode between R3 and the GPIO contacts otherwise the condenser discharge through the GPIO and is unable to be charged. The parameters for about 5 min interval that we needed is 1.1 MOhm resistence and 220 microF condenser.

    On the raspberry I used the wiringPi routines and a task in the crontab to activate the watchdog reset every 1 min.

    • ANKIT JAIN says:

      hi @Alessandro, i want to use this circuit with raspberry.
      Can you help me to share how to do that.

  5. Alessandro A says:

    Jain i replied to your question but my reply was not yet approved by the moderator…

  6. Alessandro A says:

    Jain if you send me an email i will reply you directly: gmail account

    alessandro . annunziato (at) gmail . com

    Remove the spaces and use at symbol for e mail

  7. Patrick says:

    Hi Alex,

    I’m starting with Arduino and my first project is to make a control unit for a personal lathe.
    As it’s a important system, I want to have a wachdog that reset the Arduino and shutdown the motor of the lathe in case of problem.
    So I was searcching a already made project (that’s what’s great with Arduino) and found your project.

    I have a question on how it works.
    The output D0 is flipping up and down at each Arduino Cycle.
    What if the SW crash with D0 at low level?
    The external WD won’t work ?

Leave a Reply

Your email address will not be published. Required fields are marked *