Why Does My ESP32 Keep Resetting? Brownout, Watchdog and Crash Fixes
Random reboots, boot loops and “Brownout detector was triggered”. Here’s how to read what your ESP32 is telling you, find the real cause and fix it for good.
The short answer
An ESP32 that keeps resetting almost always has one of four problems: power (a brownout), a watchdog timeout, a crash (Guru Meditation Error) or a boot problem with the strapping pins. The chip tells you which one every time it restarts. Learn to read that message and you’re halfway to the fix.
Few things are as frustrating as a board that works on the bench and reboots in the field, or one that restarts the moment Wi-Fi connects. This guide walks through how to find the real cause, with a decoder you can paste your serial log into, a calculator that checks whether your power supply is up to the job, and the fixes we use on production boards. It covers the original ESP32; the S2, S3 and C3 behave similarly, with different pins and limits where noted.
Step 1: read the reset reason
Open the serial monitor at 115200 baud and watch the first lines after a reset. The ROM bootloader always prints a line like this:
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
The rst: part is the hardware reset cause; the boot: part shows the strapping-pin state, which matters for boot problems. Look at the lines just before the reset too: messages like “Brownout detector was triggered” or “Guru Meditation Error” appear there, and they’re usually more specific than the reset code.
Your firmware can also ask the chip why it restarted, which is invaluable for devices in the field where nobody’s watching the serial port:
#include "esp_system.h"
const char *reset_reason_name(void) {
switch (esp_reset_reason()) {
case ESP_RST_POWERON: return "power-on";
case ESP_RST_BROWNOUT: return "brownout";
case ESP_RST_PANIC: return "crash (panic)";
case ESP_RST_TASK_WDT: return "task watchdog";
case ESP_RST_INT_WDT: return "interrupt watchdog";
case ESP_RST_WDT: return "other watchdog";
case ESP_RST_SW: return "software restart";
case ESP_RST_DEEPSLEEP: return "deep sleep wake";
case ESP_RST_EXT: return "external reset (EN pin)";
default: return "other/unknown";
}
}
This works in both ESP-IDF and the Arduino core. Print it at startup, or save it and include it in your device’s telemetry.
| Boot log (ROM) | What it usually means |
|---|---|
0x1 POWERON_RESET | Normal power-up. If it appears while the board is running, the supply dropped to near zero: a loose cable or a badly overloaded supply. |
0xc SW_CPU_RESET | Restarted by software: esp_restart(), or the system restarting after a crash or brownout. Check the lines above it. |
0x5 DEEPSLEEP_RESET | Woke from deep sleep. Normal if you use deep sleep. |
0x7 / 0x8 TG0/TG1WDT_SYS_RESET | A hardware watchdog timer fired: something blocked for far too long. |
0xf RTCWDT_BROWN_OUT_RESET | Brownout: the supply voltage sagged too low. |
0x10 RTCWDT_RTC_RESET | Common right after power-up or flashing. If it repeats in a loop, suspect power or flash problems. |
Paste your serial log
Paste the output from your serial monitor, everything from just before the reset to the boot line after it, or try one of the examples. The decoder runs entirely in your browser.
Cause 1: brownout (the most common)
Symptoms: the board resets when Wi-Fi or Bluetooth connects, when a relay clicks or a motor starts, when the battery is getting low, or only with a particular USB cable. The log shows Brownout detector was triggered.
Why it happens: the ESP32 is rated for 3.0–3.6 V, and its brownout detector resets the chip when the supply falls below about 2.43 V (the default level; it can be set as high as about 2.8 V). Wi-Fi transmission draws current peaks of a few hundred milliamps. Every bit of resistance between the supply and the chip (the USB cable, breadboard jumpers, thin PCB traces) drops voltage during those peaks. That’s Ohm’s law and Kirchhoff’s voltage law at work: see our Kirchhoff’s laws guide for the same effect with a motor.
The classic trap: AMS1117 on a LiPo battery
Many ESP32 boards use an AMS1117 regulator, which needs about 1.1 V more at its input than at its output under load. From USB (5 V) that’s fine. From a 3.7 V LiPo it can’t hold 3.3 V at all: under a Wi-Fi peak its output falls to roughly 2.4–2.6 V, right at the brownout threshold. Battery projects need a low-dropout regulator, or a buck-boost converter.
Will your setup brown out?
How to fix a brownout
- Use a short, thick USB cable and a supply rated for at least 500 mA. Long, thin “charging” cables can have well over 0.5 Ω round trip.
- Add bulk capacitance close to the module: for example 100–470 µF electrolytic or tantalum on the 3.3 V rail, plus the usual 10 µF and 100 nF ceramics right at the pins. They supply the fast current peaks the regulator and cable can’t.
- Choose the right regulator: a low-dropout type rated for at least 500 mA, or a buck converter. Avoid AMS1117 on single-cell batteries.
- Power motors, relays, LED strips and servos separately, and give them their own ground return (a “star” ground), so their current doesn’t flow through the ESP32’s ground.
- Put a flyback diode across every relay coil and DC motor. Without one, the voltage spike when it switches off can reset the chip.
- Get off the breadboard for anything that draws real current: jumper wires and worn breadboard contacts add surprising resistance.
Don’t just disable the brownout detector
A widely shared snippet turns the detector off. The resets stop, but the chip keeps running below its rated voltage, where flash writes can corrupt and crashes become random and far harder to trace. Use it only briefly, to confirm that power is the problem, then fix the supply.
Cause 2: watchdog timeouts
Watchdogs are timers that reset the chip if your code stops responding. ESP-IDF has two you’re likely to meet:
| Watchdog | Default timeout | Fires when | Log shows |
|---|---|---|---|
| Task watchdog | 5 s | A watched task (by default the idle tasks) doesn’t get to run in time | task_wdt: Task watchdog got triggered |
| Interrupt watchdog | 300 ms | Interrupts are blocked too long: a slow interrupt handler, or interrupts left disabled | Interrupt wdt timeout on CPU0 |
The usual cause is a loop that never gives the scheduler a chance to run other tasks:
Triggers the task watchdog
while (!sensor_ready()) {
// busy-wait: nothing else can run
}
Lets other tasks run
while (!sensor_ready()) {
vTaskDelay(pdMS_TO_TICKS(10)); // or delay(10) in Arduino
}
Fixes: add a short delay inside polling loops; move long jobs (big file writes, image processing, long HTTP calls) into their own task; keep interrupt handlers short and defer work to a task. If a task genuinely needs to run a long, deliberate operation, subscribe it to the watchdog and call esp_task_wdt_reset() at safe points, rather than raising the timeout.
Cause 3: crashes (Guru Meditation Error)
When the CPU hits something it can’t handle, ESP-IDF prints a Guru Meditation Error with an exception type, registers and a backtrace, then restarts. The exception type points you at the kind of bug:
| Exception | Usual cause | Where to look |
|---|---|---|
LoadProhibited / StoreProhibited | Reading or writing through a bad pointer, very often NULL | Uninitialised pointers, freed memory, objects used before begin() |
InstrFetchProhibited | Jumping to an invalid address | Bad function pointers or callbacks, corrupted stack |
IllegalInstruction | Executing garbage | Stack corruption, or a function that should return a value but doesn’t |
IntegerDivideByZero | Division by zero | Averages and rates computed from a count that can be 0 |
Cache disabled but cached memory region accessed | An interrupt handler running code or data from flash while flash is busy | Mark ISR functions IRAM_ATTR and keep their data in RAM |
Stack overflow in task … | A task ran out of stack | Increase that task’s stack size; avoid large local arrays and deep recursion |
abort() was called | An assert or ESP_ERROR_CHECK failed | The line above names the failing check and its error code |
Turn the backtrace into a line number
A backtrace is a list of addresses like 0x400d1a2c:0x3ffb1f80. Decoded against your firmware’s ELF file, each one becomes a function name and source line:
- ESP-IDF:
idf.py monitordecodes automatically. - PlatformIO: add
monitor_filters = esp32_exception_decodertoplatformio.ini, and build in debug mode for best results. - Arduino IDE: use an ESP exception decoder tool and paste the backtrace in.
The first line that’s in your code is usually where the problem starts.
Cause 4: boot loops and strapping pins
If the board never gets as far as running your code, or loops with messages like invalid header: 0xffffffff or flash read err, look at the strapping pins. The ESP32 reads them at the instant it comes out of reset to decide how to boot:
| Pin | At boot it selects | Common mistake |
|---|---|---|
| GPIO0 | Low = download (flashing) mode, high = run | A button or sensor holding it low: the board sits waiting for download |
| GPIO2 | Must be low or floating to enter download mode | An external pull-up that stops flashing |
| GPIO12 (MTDI) | Flash supply voltage: high = 1.8 V | A pull-up or connected device pulling it high: 3.3 V flash then fails to boot |
| GPIO15 (MTDO) | Low silences the boot log | Pulled low, so the board seems “dead” on the serial port |
Pins differ on the S2, S3 and C3, so check your module’s datasheet. Also give the EN (enable) pin a clean reset: Espressif recommends an RC delay (for example 10 kΩ pull-up and 1 µF to ground) so the chip starts only after the supply is stable. A noisy or slow EN line causes random resets that look like software bugs.
Resets that are perfectly normal
- Opening the serial monitor. Most USB–serial adapters toggle DTR/RTS, which pulse EN and GPIO0. One reset when you connect is expected.
- Waking from deep sleep. Deep sleep ends with a reset:
DEEPSLEEP_RESETandESP_RST_DEEPSLEEP. - Right after flashing. The upload tool resets the chip to start your new firmware.
For professionals: catching resets in the field
- Record the reset reason and send it home. Store
esp_reset_reason(), a reset counter and uptime in NVS or RTC memory, and include them in telemetry. A fleet-wide jump in brownouts after a hardware change tells you more than any bench test. - Enable core dumps to flash. With the core dump option set to flash in menuconfig, a crashed device saves its state; read it back later with
idf.py coredump-infoto get the backtrace and task states from a unit you can’t watch live. - Scope the rail, don’t guess. Probe 3.3 V at the module pins (with a short ground spring, not the long lead) and trigger on a falling edge around 3.0 V. Add a small shunt resistor to see current at the same time.
- Raise the brownout level deliberately. A higher threshold resets earlier, which is safer for devices that write to flash, at the cost of less battery headroom. Make it a design decision, not an accident.
- Watch the heap. Log
esp_get_free_heap_size()andesp_get_minimum_free_heap_size()over time: a steady decline is a leak that will end in a crash days later.
Debugging checklist
- Read the reset reason and the line just before it.
- Brownout? Measure the 3.3 V rail under load, then fix the supply, cable, regulator and capacitors.
- Watchdog? Find loops and waits that never yield; check slow interrupt handlers.
- Guru Meditation? Decode the backtrace and look at the first line in your code.
- Boot loop? Check GPIO0, 2, 12 and 15, the EN circuit and the flash settings.
- Still random? Log the reset reason and free heap over time, and enable core dumps.
Diagnose these
Each one is a real-world pattern. Decide on the cause before opening the answer.
1The board works on USB but resets every time it connects to Wi-Fi when running from a single LiPo cell through the onboard AMS1117.
Brownout. The AMS1117 needs about 1.1 V of headroom, so from 3.7 V it can’t hold 3.3 V during Wi-Fi peaks. Use a low-dropout regulator or a buck-boost converter.
2Every few seconds: task_wdt: Task watchdog got triggered … IDLE0 (CPU 0).
Task watchdog. Something on CPU 0 never lets the idle task run, typically a polling loop without a delay. Add vTaskDelay() or move the work into its own task.
3Guru Meditation Error: LoadProhibited, right after adding a new display library.
Bad pointer. Usually the display object is used before it’s initialised, or a pointer is NULL. Decode the backtrace to find the line.
4After adding a pull-up resistor on GPIO12 for a sensor, the board won’t boot and shows flash read err.
Strapping pin. GPIO12 high at boot selects 1.8 V flash. Move the sensor to another pin, or burn the flash-voltage eFuse only if you really understand the consequences.
5The device resets only when a relay switches off, never when it switches on.
Inductive spike. With no flyback diode across the relay coil, the coil’s collapsing magnetic field creates a voltage spike when it switches off. Add a diode (cathode to the positive side) across the coil.
Summary
- Always start with the reset reason: the serial log and
esp_reset_reason()tell you which of the four causes you’re facing. - Brownout is the most common: fix the supply, cable, regulator and capacitors, don’t disable the detector.
- Watchdogs catch code that never yields; Guru Meditation errors need a decoded backtrace; boot loops usually mean a strapping pin.
- In products, log reset reasons and enable core dumps so field failures can be diagnosed remotely.
Building an ESP32 product and want a second pair of eyes on the power design or firmware? That’s exactly what we do. Questions about your own resets are welcome in the comments below.
Frequently asked questions
Why does my ESP32 reset when Wi-Fi connects?
Almost always a power problem. The radio draws current peaks of a few hundred milliamps, and a weak supply, thin USB cable or high-dropout regulator lets the 3.3 V rail sag until the brownout detector resets the chip. Use a short, good cable, a regulator rated for at least 500 mA, and bulk capacitance near the module.
What does “Brownout detector was triggered” mean?
The ESP32’s supply voltage briefly fell below the brownout threshold (about 2.43 V at the default setting), so the chip reset itself to avoid running unreliably. It points to the power supply, wiring or a current-hungry load, not to your code.
Is it safe to disable the ESP32 brownout detector?
It stops the resets but not the cause. Running below the rated voltage can corrupt flash writes and cause random crashes that are far harder to debug. Fix the power supply instead; disable the detector only as a short-term diagnostic.
How do I fix “Task watchdog got triggered” on ESP32?
A task ran too long without letting the scheduler run. Add a short delay or vTaskDelay() inside long loops, move heavy work to its own task, and avoid blocking waits. Only feed the watchdog manually for genuinely long, deliberate work.
How do I find which line caused a Guru Meditation Error?
Decode the backtrace. idf.py monitor does it automatically; in PlatformIO add monitor_filters = esp32_exception_decoder; in the Arduino IDE use an ESP exception decoder. Each address becomes a function name and line number.
Comments
No comments yet. Questions, corrections and your own tips are all welcome.