Home › Lessons › Embedded (ESP32) › Watchdog timer

Watchdog timer

Embedded (ESP32) · Intermediate · about 20 minutes · part of Zen’s Electronics Design Mastery

Field devices hang: a sensor stops answering, a network call never returns. A watchdog is a hardware timer the program must reset regularly; if it ever runs out, the chip reboots itself and the device recovers on its own.

Watchdog timer: the circuit on the simulator's bench

Open this lesson in the labFree, in your browser, no account needed.

How it works

loop() calls esp_task_wdt_reset() every 500 ms, well inside the 3 s timeout. Press the button and the sketch gets stuck in a loop that never resets it. 3 s later the task watchdog fires and the ESP32 reboots (reset reason TG0WDT_SYS_RESET), then carries on normally.

Pick a timeout longer than the slowest legitimate operation (a Wi-Fi connect can take several seconds) but short enough to recover quickly.

Try it on the bench

  1. Click the Hang button once. The serial output stops, then about 3 s later the chip reboots and recovers.
  2. Edit the sketch to remove esp_task_wdt_reset(): it now reboots every 3 s even without a hang.

Parts on the bench

In the course

Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.

More on embedded (esp32)