ESP32 WiFi scan: how to find and connect to networks
When WiFi won’t connect, scanning is your best “reality check.” It tells you:
- Is your SSID actually visible from where the ESP32 is?
- Is it strong enough to be stable?
- Are you accidentally targeting a 5GHz-only network name?
ESP32 WiFi scan sketch
#include <WiFi.h>
void setup() {
Serial.begin(115200);
delay(200);
WiFi.mode(WIFI_STA);
WiFi.disconnect(true); // ensure we start “clean”
delay(200);
Serial.println("Scanning...");
int n = WiFi.scanNetworks();
if (n <= 0) {
Serial.println("No networks found.");
return;
}
Serial.print("Found ");
Serial.print(n);
Serial.println(" networks:");
for (int i = 0; i < n; i++) {
Serial.print(i + 1);
Serial.print(") ");
Serial.print(WiFi.SSID(i));
Serial.print(" RSSI: ");
Serial.print(WiFi.RSSI(i));
Serial.print(" dBm ");
Serial.print(" Encryption: ");
Serial.println((int)WiFi.encryptionType(i));
delay(10);
}
}
void loop() {}How to use the scan results
- Find your SSID in the list and check RSSI.
- If RSSI is worse than about -70 dBm, move the ESP32 closer before troubleshooting code.
- If you don’t see your SSID at all, check your router (2.4GHz enabled, SSID broadcast enabled) or try a different location.
Connecting after a scan
Once you know the SSID is visible and strong, use the minimal connection sketch from the WiFi connect FAQ and build from there.
Bottom line
Scan first. If your network isn’t visible (or RSSI is terrible), no amount of code tweaking will fix it.
Related: Connect ESP32 to WiFi · Weak signal / connection failed · Disconnects / stays disconnected