Summary: In this Instructable we look at how to build more reliable computer systems using WatchDog timers. We show how to set up and use the Raspberry Pi and Arduino internal watchdog timers. We also explain why an external WatchDog Timer is a better choice in many, but not all, systems.

See more on WatchDog Timers in Solar Power applications on www.switchdoc.com.

Step 1 - Introduction to WatchDog Timers

Step 2 - How to Set Up the Raspberry Pi Internal WatchDog Timer

Step 3 - How to Set Up the Arduino Internal WatchDog Timer

Step 4 - Internal Versus External WatchDog Timers / Issues with Internal Timers

Step 5 - Adding an External WatchDog Timer to your Project

Step 6 - Suggestions for Educators and Conclusion


In this Instructable you will learn how:

  • What are WatchDog Timers and Why they are Cool
  • How To use the Raspberry Pi Internal Watchdog Timer
  • How to use the Arduino Internal WatchDog Timer
  • Compare and Contrast Internal Versus External WatchDog Timers
  • How to use an External WatchDog Timer
  • Suggestions for Student Experiments with WatchDog Timers

Step 1: Introduction to WatchDog Timers

Introduction to WatchDog Timers

Computers sometimes lose their way. A power glitch, RFI (Radio Frequency Interference), hanging peripherals, or just plain bad programming can cause your small computer to hang causing your application to fail. It happens all the time. How often do you have to reboot your PC? Not very often, but once in while your Mac or PC will freeze making you have to power cycle the computer. Raspberry Pi's will sometimes freeze because of a task not freeing up sockets or consuming other system resources and from power supply fluctuations. Arduinos sometimes freeze because of brownouts on the power line or a short power interruption or because of running out of system resources such as RAM and/or stack space, which is a very limited resource in an Arduino. Sometimes even programmers (gasp!) make mistakes.

See the WatchDog Timer and Computer Block Diagram above.

In small computers, you can give your device the chance to recover from faults by using what is called a WatchDog Timer (WDT). A WDT is an electronic timer that is used to detect and recover from computer malfunctions. If the computer fails to reset the timer (also called “patting the dog”) on the WDT before the WDT timer expires, the WDT signal is used to initiate either corrective actions or simply to reboot the computer.

Will the use of a WatchDog Timer make your computer project more reliable? The answer is yes. The proper use of a WatchDog timer can make your computer reboot when it gets lost. A known problem with some Python libraries on the Raspberry Pi is that some of those libraries don't properly release sockets and after a long period of time (days generally - not weeks) the Raspberry Pi will hang or thrash because it is out of resources. A properly designed program could detect this and reboot the computer, but a WatchDog Timer can be used to cover a whole multitude of sins with one fell swoop.

In Project Curacao, we use a WatchDog Timer to reset the Battery Power Watchdog in case of a brownout or an RFI upset event.

In our WeatherPi Instructable (https://www.instructables.com/id/Create-Your-Own-Solar-Powered-Raspberry-Pi-Weather/) we use the WatchDog Timer to make sure the Raspberry Pi power is shut off after a "shutdown -h now" halt and also to detect the computer getting lost. More reliablity!

About This Instructable




Bio: SwitchDoc Labs, LLC is a software and hardware engineering company producing specialized products and designs for the small computer industry maker movement (Raspberry Pi, Arduinos ... More »
More by SwitchDocLabs:GroveWeatherPi - Solar Raspberry Pi Based Weather Station - No Soldering Required (Updated October 24, 2016) Build a Solar Powered ESP8266 Using XML on the Raspberry Pi with Python 
Add instructable to: