Watchdog timer
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.

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
- Click the Hang button once. The serial output stops, then about 3 s later the chip reboots and recovers.
- Edit the sketch to remove esp_task_wdt_reset(): it now reboots every 3 s even without a hang.
Parts on the bench
- Bench power supply
- ESP32 DevKit
- USB charger / port
- Push button
In the course
Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.