ESP8266 Random Reset/Reboot
Your ESP8266 randomly resets or reboots during operation. The device may work for minutes or hours then suddenly restart. This guide covers watchdog timer triggers, brownout detection, power supply issues, memory corruption, and code problems causing unexpected resets.
Last updated: April 22, 2026 | 12 min read
Symptoms
- ESP8266 reboots randomly during normal operation
- Serial Monitor shows "wdt reset" or "Soft WDT reset" messages
- Device resets when WiFi connects or disconnects
- Resets occur when relays activate or sensors read
- Brownout detector messages before reboot
- Device works fine for hours then suddenly resets
- Reset occurs at same point in code execution
Common Causes
- Watchdog Timer Timeout Most common issue. loop() blocks for >3 seconds without yielding. ESP8266 watchdog resets the chip
- Power Supply Brownout Voltage drops below 2.8V during WiFi transmission or relay activation. Current spikes of 300-400mA cause voltage sag
- Stack Overflow or Memory Corruption Large local arrays or recursion overflow the 4KB stack. String concatenation in loops causes heap fragmentation
- Infinite Loop Without yield() while or for without calling yield() blocks watchdog
- Interrupt Service Routine Too Long ISRs must be very short; long ISRs cause watchdog reset
- WiFi Reconnection Loop Blocking WiFi reconnect code without timeout
- Faulty Hardware Damaged ESP8266 or poor solder joints
ESP8266 Reset Reasons
| Reset Reason Code | Meaning | Solution |
|---|---|---|
| wdt reset () | Watchdog timeout () | Add yield() in loops, reduce delay() |
| Soft WDT reset () | Software watchdog triggered () | Same as wdt reset, add yield() ) |
| Brownout detector () | Power supply voltage dropped () | Upgrade power supply, add capacitor (,) |
| Fatal exception 28 | LoadProhibited - invalid memory access () | Check pointers, array bounds (,) |
| Fatal exception 29 | StoreProhibited - writing to invalid memory () | Check array bounds, null pointers (,) |
| Fatal exception 0 | Illegal instruction () | Corrupted flash, re-flash firmware (,) |
Step-by-Step Fixes
1. Add yield() in Loops
Watchdog resets if loop() blocks for >3 seconds:
// WRONG - Blocks watchdog
void loop() {
for {
// Long operation...
}
delay; // Too long!
}
// CORRECT - Feed watchdog with yield()
void loop() {
for {
if {
yield(); // Feed watchdog every 1000 iterations
}
}
// Break long delays into smaller chunks
for {
delay; // 100ms chunks instead of 1000ms
yield();
}
}
2. Fix Power Supply Issues
WiFi transmission draws high current :
- Use 5V 1A power supply minimum
- Add 470-1000F capacitor between 5V and GND
- Use quality USB cable
- Power relays from separate 5V supply
- Measure voltage at 3.3V pin must stay above 2.8V during WiFi
// Optional: Reduce WiFi TX power to lower current draw
#include <ESP8266WiFi.h>
void setup() {
WiFi.begin(ssid, password);
// Reduce TX power
// 20 = 5dBm
// 40 = 10dBm
// 60 = 15dBm
// 78 = 19.5dBm
WiFi.setOutputPower; // 10dBm - reduces current by ~30%
}
3. Detect Reset Reason
Identify what's causing the reset:
#include <Esp.h>
void printResetReason() {
rst_info* resetInfo = ESP.getResetInfoPtr();
Serial.print;
switch {
case REASON_DEFAULT_RST:
Serial.println");
break;
case REASON_WDT_RST:
Serial.println");
break;
case REASON_EXCEPTION_RST:
Serial.println;
break;
case REASON_SOFT_WDT_RST:
Serial.println");
break;
case REASON_SOFT_RESTART:
Serial.println called");
break;
case REASON_DEEP_SLEEP_AWAKE:
Serial.println;
break;
default:
Serial.print;
Serial.println;
}
}
void setup() {
Serial.begin;
printResetReason(); // See why device reset
}
4. Avoid Blocking WiFi Operations
WiFi connection can block and trigger watchdog:
// WRONG - Blocks watchdog during connection
void connectWiFi() {
WiFi.begin(ssid, password);
while != WL_CONNECTED) {
delay; // This can block for 10+ seconds!
}
}
// CORRECT - Non-blocking with timeout
void connectWiFi() {
WiFi.begin(ssid, password);
int attempts = 0;
while != WL_CONNECTED && attempts < 40) {
delay;
yield(); // Feed watchdog
attempts++;
Serial.print(".");
}
if == WL_CONNECTED) {
Serial.println;
} else {
Serial.println;
}
}
5. Prevent Stack Overflow
Large local arrays cause stack overflow:
// WRONG - 4KB array on stack
void processData() {
uint8_t buffer[4096]; // Stack overflow!
}
// CORRECT - Use heap instead
void processData() {
uint8_t* buffer = malloc;
if {
Serial.println;
return;
}
// Use buffer...
free; // Always free!
}
6. Keep Interrupt Service Routines Short
Long ISRs cause watchdog resets:
// WRONG - Long ISR
ICACHE_RAM_ATTR void buttonISR() {
delay; // NEVER use delay in ISR!
digitalWrite;
delay;
digitalWrite;
}
// CORRECT - Set flag in ISR, process in loop
volatile bool buttonPressed = false;
ICACHE_RAM_ATTR void buttonISR() {
buttonPressed = true; // Just set flag
}
void loop() {
if {
buttonPressed = false;
// Do slow stuff here
digitalWrite;
delay;
digitalWrite;
}
}
7. Monitor Free Heap Memory
Memory leaks cause eventual crashes:
void setup() {
Serial.begin;
Serial.print;
Serial.println);
}
void loop() {
static unsigned long lastMemCheck = 0;
if (millis() - lastMemCheck > 30000) { // Every 30 seconds
lastMemCheck = millis();
int freeHeap = ESP.getFreeHeap();
Serial.print;
Serial.println;
if {
Serial.println;
// Take action - restart or free memory
}
}
// Your code here...
}
Prevention Tips
- Always call yield() in long loops
- Keep delays under 1000ms; break long delays into chunks with yield()
- Add 470-1000F capacitor between 5V and GND for power stability
- Use external power supply for relays
- Avoid large local arrays; use malloc()/free() for heap allocation
- Keep ISRs extremely short
- Monitor free heap memory; restart if memory gets low
Related Issues
Frequently Asked Questions
Q: What does "wdt reset" mean on ESP8266?
A: Watchdog timer reset. The ESP8266 has a hardware watchdog that resets the chip if the main loop doesn't yield within ~3.2 seconds. Add yield() calls in long loops or break up long delays.
Q: Device resets only when WiFi is active. Why?
A: Power supply issue. WiFi transmission draws high current causing voltage drop. Add 470-1000F capacitor between 5V and GND, or use stronger power supply.
Q: How do I read the reset reason after reboot?
A: Use ESP.getResetInfoPtr() in setup(). The reset reason is stored in RTC memory and survives reboot. Print it to Serial Monitor to see why device reset.
Still having reset issues? Contact Support or return to the Troubleshooting Hub.