Why Your ESP32 Wi-Fi Keeps Dropping (and How to Fix It Permanently)

Why Your ESP32 Wi-Fi Keeps Dropping (and How to Fix It Permanently)

An ESP32 that connects once, then drops, reconnects, or loses packets is rarely a faulty chip. In almost every case, the cause is one of five things: weak power, bad antenna placement, wrong Wi-Fi power-save settings, a missing reconnect routine, or interference from your own 2.4 GHz network.

The real reason ESP32 Wi-Fi feels unreliable

The ESP32 shares its 2.4 GHz radio between Wi-Fi and Bluetooth. Every time the radio has to switch tasks, current spikes to hundreds of milliamps. If your power supply cannot absorb those spikes, the chip browns out, the Wi-Fi stack resets, and from the outside it looks like the Wi-Fi "dropped." So before you blame the router, look at the power rail.

1\. Power supply: the number-one hidden cause

A USB phone charger rated for 1 A is not enough in practice. The ESP32 needs a stable 3.3 V, and the on-board LDO needs headroom. When the radio transmits, the current spike can pull the rail down and trigger the brownout detector.

  • Use a supply rated for at least 1 A continuous, 2 A peak.
  • Add a 470 ยตF to 1000 ยตF electrolytic capacitor close to the 3.3 V pin, plus a 100 nF ceramic in parallel.
  • Avoid powering the ESP32 from a laptop USB hub โ€” those ports often limit to 500 mA.
  • If you use a battery, check the regulator's quiescent current and drop-out voltage.

2\. Antenna placement inside enclosures

The PCB antenna on most ESP32 dev boards is a small meander at the end of the board. Anything conductive near it โ€” a metal case, a battery, a ribbon cable, or your hand โ€” detunes it and kills range.

  • Keep at least 15 mm of empty space in front of the antenna.
  • Never place the antenna against a metal enclosure or a ground plane.
  • Cut a slot in plastic enclosures at the antenna location.
  • For long-range nodes, switch to a board with a U.FL connector and an external 2.4 GHz antenna.

3\. Wi-Fi power-save mode

By default the ESP32 Arduino core leaves modem sleep enabled. That is fine for battery nodes but causes dropped packets and high latency on always-on devices. For a mains-powered sensor or controller, disable it:

#include <WiFi.h>

void setup() {
  WiFi.mode(WIFI_STA);
  WiFi.setSleep(false);          // disable modem sleep
  WiFi.setAutoReconnect(true);   // reconnect automatically
  WiFi.persistent(true);
  WiFi.begin("SSID", "password");
}

On older cores, WiFi.setSleep(false) may need to be called after WiFi.begin(). Test both orders if you still see drops.

4\. Add a reconnect watchdog

Even with the fixes above, a router reboot will still disconnect you. The ESP32 will not always rejoin on its own if the disconnect happened during a long blocking loop. Add a simple watchdog:

unsigned long lastCheck = 0;
const unsigned long CHECK_INTERVAL = 10000; // 10 s

void loop() {
  if (millis() - lastCheck > CHECK_INTERVAL) {
    lastCheck = millis();
    if (WiFi.status() != WL_CONNECTED) {
      Serial.println("Wi-Fi lost, reconnecting...");
      WiFi.disconnect();
      WiFi.begin("SSID", "password");
    }
  }
  // your normal code here, no long delays
}

Avoid delay(5000) in your main loop โ€” during that time the Wi-Fi stack cannot service the connection.

5\. Interference from your own network

The 2.4 GHz band is crowded. Microwaves, Zigbee, Bluetooth speakers, baby monitors and neighbouring routers all share it. Two practical steps help:

  • Set your router to channel 1, 6 or 11 only, and pick the one with the least overlap.
  • If your router is dual-band, move phones, laptops and TVs to 5 GHz and leave 2.4 GHz for IoT devices.
  • Keep the ESP32 at least one metre away from the router โ€” too close can be as bad as too far.

How to prove which cause you have

Log the RSSI and the disconnect reason in code. The ESP32 exposes both:

Serial.printf("RSSI: %d dBm\n", WiFi.RSSI());
Serial.printf("Disconnect reason: %d\n", WiFi.getDisconnectReason());

Common reason codes:

  • 2 โ€” auth expired (wrong password or router reboot).
  • 4 โ€” association timeout (weak signal or interference).
  • 200 โ€” beacon timeout (router dropped you or power issue).
  • 201 โ€” no AP found (antenna or range problem).

Aim for RSSI better than โˆ’70 dBm. Below โˆ’80 dBm, expect drops even with perfect code.

What about a mesh or repeater?

If the ESP32 sits in a garage or garden shed, do not try to fix it with code. Add a proper access point or mesh node nearby. A cheap travel router in AP mode, wired back to the main network with Ethernet, will outperform any Wi-Fi extender and cost less than a wasted weekend of debugging.

Summary

ESP32 Wi-Fi drops are almost always one of: weak power, bad antenna placement, modem sleep, no reconnect logic, or 2.4 GHz congestion. Fix the power rail first, keep the antenna clear, disable sleep, add a watchdog, and pick a clean channel. Do those five things and your node will stay online for months.

Comments