All notes
Firmware2 min read

Why my ESP32 kept rebooting: blocking sounds and the task watchdog

After adding distinct buzzer and LED patterns for each event (valid tap, unknown card, errors), the device started rebooting at random.

What was happening

The ESP32 runs a task watchdog. If a task hogs the CPU too long without yielding, the watchdog resets the chip. My sound and LED functions used blocking delays, and calling them back to back kept the task busy for too long.

The fix

I added a yield() roughly every 40 ms inside those functions, so the watchdog gets fed and other tasks can run.

// inside a blocking beep/blink loop
if (millis() - lastYield >= 40) {
  yield();
  lastYield = millis();
}

Lesson: a delay that is fine in isolation can add up when feedback patterns chain together.