ESP32 Wi-Fi keeps disconnecting: stable connection checklist

A connection that drops after it was working usually needs reconnect code, a steadier supply or a stronger signal. Do not assume WiFi.begin() once at start-up is enough.

What the message means

The ESP32 can lose the access point for many reasons: weak signal, a router that drops idle clients, a supply dip during radio bursts, or a long blocking loop. The board does not always reconnect on its own unless you ask it to.

Fix it in this order

  1. Call WiFi.setAutoReconnect(true) and also check WiFi.status() in loop(). If it is not connected, call WiFi.reconnect().
  2. Turn off Wi-Fi power saving with WiFi.setSleep(false) while you debug. It can reduce dropped connections at the cost of more current.
  3. Check the supply. Radio bursts draw current peaks, and a weak USB port or thin wire causes dropouts and resets.
  4. Move closer to the router or fix the antenna. A weak signal looks like random disconnects.
  5. Avoid long delay() calls and blocking loops. Keep loop() short so the Wi-Fi tasks get time.
  6. Check the router: too many clients, a short DHCP lease or a channel crowded with neighbours can drop devices. Try a fixed channel.
  7. Print the disconnect reason from the Wi-Fi event handler. It tells you if the access point kicked the board or the signal was lost.

Why it happens

Wi-Fi drops on an ESP32 usually come from a weak supply, a poor signal, the radio power-save mode, or code that never reconnects. The radio draws short, large current bursts, so a weak USB cable or port can cause brown-outs that look like disconnects.

Use a good supply with a capacitor near the board, move closer to the router, and add a reconnect step in code.

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.disconnect();
    WiFi.reconnect();
    delay(5000);
  }
}
// WiFi.setSleep(false); in setup() turns off power-save if drops continue

Example sketch: change pins and values for your own wiring. It has not been bench-tested on your hardware.

If you see this, do this

You seeDo this
Drops every few minutesRouter lease or power-saving settings.
Drops when the motors runSupply dip. Separate the motor supply.
Drops far from the routerSignal strength.

ESP32 will not connect to Wi-Fi, ESP32 brownout, Wi-Fi controlled robot with ESP32.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

After a successful join the ESP32 keeps the link alive by listening for the router’s beacon frames. If it misses several in a row, it decides the router is gone and reports a disconnect with the reason code BEACON_TIMEOUT (200). Other codes name other events: NO_AP_FOUND (201) means the name was not seen when it tried to rejoin, and AUTH_FAIL (202) means authentication was refused.

A missed beacon has physical causes. The signal is weak, the radio is starved because the supply sagged during a transmit burst, or the sketch blocks the CPU so Wi-Fi tasks cannot run on time. Power-save mode makes the radio sleep between beacons, so it saves current but gives the router less contact. The reason code and the circumstances of the drop together point to the cause.

How to confirm the cause

  • Register a Wi-Fi event handler and print the reason code every time a disconnect happens. Record the code and the time since boot.
  • Print WiFi.RSSI() every few seconds. A reading sliding toward minus 80 dBm before a drop points to range.
  • Note whether drops coincide with motor starts or servo moves. If so, the supply is dipping and not the router.
  • Run the board from a known good supply for an hour with the motors off. If it stays up, the load is the cause.
  • Check the router’s client list and logs for the lease time and any repeated reconnects.

Worked example

This handler prints why each disconnect happened. Add it to setup() before WiFi.begin().

void onWifi(WiFiEvent_t event, WiFiEventInfo_t info) {
  if (event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
    Serial.printf("lost link, reason %d, uptime %lu s\n",
      info.wifi_sta_disconnected.reason, millis() / 1000);
  }
}
void setup() {
  Serial.begin(115200);
  WiFi.onEvent(onWifi);
  WiFi.begin(SSID, PASS);
}

Reason 200 with a falling signal points to range or antenna. Reason 200 that coincides with motors points to the supply. Reason 202 after the router restarts points to a password or security change.

Common mistakes

  • Calling WiFi.begin() again every few seconds from loop(), which interrupts a join in progress.
  • Blocking loop() with long delays.
  • Powering motors from the same rail as the ESP32 with no capacitor.
  • Testing only near the router and then deploying in another room.

If this did not fix it

  • Router limits or restarts: check the router uptime and its logs.
  • Interference on a crowded channel: try a fixed channel on the router.
  • A server closing idle connections: the Wi-Fi link is fine and the problem is in the application protocol, so check keep-alive settings.