Hardware Watchdog for your Arduino Projects

What’s a Hardware Watchdog?

Basically a Hardware Watchdog is a device external to your primary controller that monitors a “heartbeat” and restarts it if the beat is not received within a specific time period.

So let us say for example you have a large array of sensors attached to an Arduino Mega mounted in an inconvenient or remote location. What if you need to ensure it keeps reporting in regardless of fault until you can get to it. By having the watchdog it can restart the device to keep it reporting until you can deal with the fault.

This is accomplished with a small sketch for the watchdog and a library for the master unit.

The Hardware Watchdog

The sketch is very small requiring only one external library. Pretty much any Arduino compatible MCU can host this code. We generally use the ultra-tiny (size of a quarter) Digispark ATTINY85. If you look around you can find clones for less than $1. It should easily fit alongside your main controller and can usually be powered from the same power supply.

ATTINY85 Hardware Watchdog

The sketch is available on our GitHub page @ https://github.com/sktaylortrash/atTiny85-Watchdog

Connection details and a link to the external library are included there.

The Heartbeat

The second part of the equation is the heartbeat signal. For this, we have created an Arduino library. https://github.com/sktaylortrash/HeartBeat

There are just a few steps to get it up and running

  1. Include the library in your main sketch.
  2. Define your pin and timer length
    • Make sure it’s not longer than what you configured the sketch for
  3. Define a function for this timer (you can have more than one)
  4. Initialize the pin in setup()
  5. Add your function to loop()

The library includes a complete example sketch.

Testing

If both devices are running, with everything connected properly. The Watchdog light should be flashing. Disconnecting the heartbeat pin triggers a restart test.


We hope you find this useful in one of your upcoming projects. My personal favourite project where this is in use is my lighting controller. We will do a writeup on that at a later date. In the meantime, we have a post on the buttons used for that available Leviton Momentary Switch Mod

You may also like...