Learn ESP32 WiFi scan with Arduino & MicroPython. Scan networks, measure signal strength, display on OLED, async scanning & troubleshooting tips.
Imagine you’re building a smart home device. Your ESP32 is ready, sensors are wired, but there’s one critical step: connecting to WiFi. Without a reliable connection, your device is just a gadget on your desk. This is where ESP32 WiFi scan comes in. Scanning networks, checking signal strength, and connecting to the right network are key to creating smart, autonomous IoT devices.
In this guide, we’ll explore ESP32 WiFi scanning step by step, with beginner-friendly examples, MicroPython integration, OLED display projects, async scanning, and troubleshooting—all optimized to help you understand and implement WiFi scanning professionally.
If you’re just getting started with ESP32 and WiFi projects, understanding how to scan WiFi networks is one of the foundational skills you need. Whether you’re building IoT projects, home automation systems, or just experimenting for fun, learning ESP32 WiFi scan techniques is essential. In this tutorial, I’ll walk you through everything from basic WiFi scanning to more advanced use cases like scanning while connected, using MicroPython, and even displaying networks on an OLED screen.
Grab your coffee, sit back, and let’s make WiFi scanning on ESP32 straightforward and enjoyable.

What is ESP32 WiFi Scan? Understanding Network Scanning on ESP32 ?
The ESP32 WiFi scan is a feature that allows your ESP32 microcontroller to detect nearby WiFi networks. This process helps you identify available networks, check their signal strength, and decide which network to connect to. Think of it as your ESP32 “looking around” to see which WiFi networks it can talk to.
Using this feature, you can:
- Automatically connect to the strongest network.
- Display nearby WiFi networks on a screen.
- Filter networks based on signal strength.
- Perform advanced tasks like scanning while connected.
This makes ESP32 extremely powerful for IoT and smart home projects.
Why Scan WiFi Networks with ESP32? Benefits and Use Cases
Before we dive into code, let’s understand why you’d want your ESP32 to scan WiFi networks:
- Automated Connections: Your ESP32 can automatically find and connect to a preferred network without hardcoding SSID and password.
- Network Selection: If multiple networks are available, your ESP32 can choose the one with the strongest signal.
- Debugging: When your ESP32 fails to connect, scanning helps you identify network issues.
- IoT Projects: For projects like smart sensors or WiFi signal strength meters, scanning networks is essential.
In short, knowing how to scan WiFi networks makes your ESP32 smarter and more autonomous.
Getting Started: ESP32 WiFi Scan Requirements and Setup
Before we start coding, make sure you have everything ready for your ESP32 WiFi scan project:
- ESP32 development board (like ESP32 DevKit v1)
- Arduino IDE or PlatformIO installed
- USB cable to connect ESP32 to your PC
- Optional: OLED display if you want to visualize scanned networks
- MicroPython installed on ESP32 (if you’re using MicroPython examples)
If you want a complete guide covering all ESP32 tutorials, from setup to advanced projects, check out this resource: ESP Tutorials Complete Guide. It’s beginner-friendly and perfect for getting your ESP32 projects up and running.
ESP32 WiFi Scan Example (Arduino IDE): Step-by-Step Guide for Beginners
Let’s start with the most basic example using Arduino IDE.
#include "WiFi.h"
void setup() {
Serial.begin(115200);
// Set ESP32 as station mode
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("ESP32 WiFi Scanner");
}
void loop() {
Serial.println("Scanning for WiFi networks...");
int n = WiFi.scanNetworks();
if (n == 0) {
Serial.println("No networks found");
} else {
Serial.println("Networks found:");
for (int i = 0; i < n; ++i) {
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(" dBm) ");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? "Open" : "Secured");
}
}
Serial.println("");
delay(5000); // Wait 5 seconds before scanning again
}
Explanation:
WiFi.mode(WIFI_STA)sets your ESP32 in station mode.WiFi.scanNetworks()scans all available WiFi networks.WiFi.SSID(i)gives the name of the network.WiFi.RSSI(i)provides the signal strength.- This is a simple ESP32 WiFi scan code to display nearby networks in the Serial Monitor.
MicroPython ESP32 WiFi Scan: Scan Networks Using Python Scripts
If you prefer MicroPython, here’s a Micropython ESP32 WiFi scan example:
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
networks = sta_if.scan()
print("Scanning for WiFi networks...")
for net in networks:
ssid = net[0].decode('utf-8')
bssid = net[1]
channel = net[2]
RSSI = net[3]
authmode = net[4]
print(f"SSID: {ssid}, RSSI: {RSSI} dBm, Channel: {channel}")
- This script will list all available networks with their signal strengths.
- MicroPython is lightweight and perfect for small ESP32 IoT projects.
ESP32 WiFi Scan While Connected: Monitor Networks Without Dropping Connection
Sometimes, you want your ESP32 to scan networks without disconnecting from the current network. Here’s how you do that:
#include "WiFi.h"
void setup() {
Serial.begin(115200);
WiFi.begin("YourSSID", "YourPassword");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting...");
}
Serial.println("Connected to WiFi");
}
void loop() {
Serial.println("Scanning for other networks...");
int n = WiFi.scanNetworks(false, true); // async scan while connected
for (int i = 0; i < n; i++) {
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.println(" dBm)");
}
delay(10000);
}
WiFi.scanNetworks(false, true)allows scanning while connected.- Useful for projects like WiFi signal strength meters or multi-network devices.
ESP32 Scan and Connect to Strongest Network: Automatic WiFi Selection
Your ESP32 can scan multiple networks and connect to the one with the strongest signal. Here’s a simple example:
#include "WiFi.h"
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
}
void loop() {
int n = WiFi.scanNetworks();
if (n == 0) {
Serial.println("No networks found");
} else {
int strongestNetwork = 0;
int strongestRSSI = -100;
for (int i = 0; i < n; i++) {
int rssi = WiFi.RSSI(i);
if (rssi > strongestRSSI) {
strongestRSSI = rssi;
strongestNetwork = i;
}
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(rssi);
Serial.println(" dBm)");
}
Serial.print("Connecting to ");
Serial.println(WiFi.SSID(strongestNetwork));
WiFi.begin(WiFi.SSID(strongestNetwork).c_str());
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting...");
}
Serial.println("Connected!");
}
delay(60000); // Scan every minute
}
- This is ideal for ESP32 devices that roam between multiple networks.
ESP32 WiFi Scanner on OLED: Display Networks and Signal Strength
Want to visualize networks directly on a small screen? Here’s how you can show scanned networks on an OLED display:
#include
#include
#include "WiFi.h"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 allocation failed");
for(;;);
}
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
}
void loop() {
display.clearDisplay();
int n = WiFi.scanNetworks();
for(int i = 0; i < n && i < 6; i++) { // Display max 6 networks
display.setCursor(0, i*10);
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.print(WiFi.SSID(i));
display.print(" ");
display.print(WiFi.RSSI(i));
}
display.display();
delay(10000);
}
- This makes your ESP32 a portable WiFi scanner.
- Great for quick WiFi surveys.
ESP32 Async WiFi Scan: Perform Non-Blocking Network Scans Efficiently
The ESP32 WiFi scan async function allows scanning without blocking other operations. Using ESPAsyncWebServer library:
#include
#include
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
server.on("/scan", HTTP_GET, [](AsyncWebServerRequest *request){
String networks = "";
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++) {
networks += WiFi.SSID(i) + " (" + String(WiFi.RSSI(i)) + " dBm)\n";
}
request->send(200, "text/plain", networks);
});
server.begin();
}
void loop() {
// Non-blocking async scan on web request
}
- Your ESP32 can serve WiFi scan results via a web interface.
- Perfect for IoT dashboards.
ESP32 WiFi Scan Config: Customize and Optimize Your Network Scans
You can configure scanning with optional parameters:
WiFi.scanNetworks(/*async=*/true, /*hidden=*/false);
async: If true, scanning does not block other operations.hidden: If true, includes hidden networks in the scan.
These options help fine-tune your ESP32 WiFi scan config for advanced projects.
Measuring Signal Strength: ESP32 WiFi Signal Strength Meter
A fun project is creating a WiFi signal strength meter:
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++) {
int rssi = WiFi.RSSI(i);
Serial.print(WiFi.SSID(i));
Serial.print(" - ");
Serial.println(rssi);
}
- Use the RSSI value to create a graphical meter on OLED or web.
- Great for finding WiFi dead spots in your home.
Combining ESP32 WiFi Scan and Connect: Automatically Join the Best Network
You can scan and immediately connect to known networks using a list:
String knownSSIDs[] = {"HomeWiFi", "OfficeWiFi"};
String knownPasswords[] = {"pass123", "office123"};
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
if (WiFi.SSID(i) == knownSSIDs[j]) {
WiFi.begin(knownSSIDs[j].c_str(), knownPasswords[j].c_str());
Serial.println("Connecting to " + knownSSIDs[j]);
break;
}
}
}
- Automatically connects to preferred networks.
- Ideal for roaming IoT devices.
ESP32 WiFi Scan Example Summary
Here’s a quick recap:
| Feature | Function |
|---|---|
| Basic Scan | WiFi.scanNetworks() |
| Scan while connected | WiFi.scanNetworks(false, true) |
| Async scan | WiFi.scanNetworks(true) |
| Scan + connect strongest | Compare RSSI values |
| Display on OLED | Adafruit_SSD1306 library |
| MicroPython scan | network.WLAN(network.STA_IF).scan() |
Best Practices for ESP32 WiFi Scan: Tips for Reliable Scanning and Connectivity
- Always disconnect before scanning to avoid stale results.
- Avoid scanning too frequently; ESP32 may reset if overworked.
- Use async scans for multitasking projects.
- Limit displayed networks if using OLED.
- Filter networks based on RSSI for better reliability.
Advanced Tips for ESP32 WiFi Scan: Boost Performance and Efficiency
- Combine ESP32 WiFi scan and connect logic to create self-healing WiFi devices.
- Use RSSI to measure distance or detect obstacles for smart IoT.
- Integrate with web dashboards for live network monitoring.
- Combine ESP32 WiFi scanner OLED with mobile apps for real-time display.
Summary of ESP32 WiFi Scan: Key Takeaways and Best Practices
Learning ESP32 WiFi scan opens up many possibilities. From simple scanning to async scans, displaying networks on OLED, and even creating WiFi signal strength meters, ESP32 is versatile and powerful.
By following these tutorials, you can:
- Understand nearby WiFi networks
- Automatically connect to the strongest network
- Display networks on OLED screens
- Debug WiFi issues
- Create smart IoT solutions
Remember, the key to mastery is experimentation. Try scanning while connected, try async scanning, and use RSSI for interesting projects.
ESP32 makes WiFi scanning easy, fun, and incredibly powerful for beginners and pros alike.
Troubleshooting ESP32 WiFi Scan: Common Questions & Expert Answers
1. Why is my ESP32 WiFi scan not working?
- Ensure
WiFi.mode(WIFI_STA)is active - Call
WiFi.disconnect()before scanning - Delay 100ms after setup to stabilize WiFi module
- Update Arduino IDE ESP32 board definitions
2. Why do I see no networks?
- Networks may be hidden; enable hidden scanning
- Distance from router may be too far
- Interference from other electronics
3. Scan works, but ESP32 can’t connect
- Check SSID and password
- Ensure WiFi channel is supported
- Check encryption type (WPA/WPA2)
4. How to scan while connected?
- Use
WiFi.scanNetworks(false, true) - Keeps current connection alive
5. Signal strength readings seem low
- RSSI is measured in dBm; negative values closer to 0 mean stronger signal
- Move closer to router to test
6. Can I scan multiple times per second?
- Avoid frequent scanning; it may cause resets
- Recommended: every 5-10 seconds
7. ESP32 WiFi scan fails after deep sleep
- Reinitialize WiFi on wakeup
- Call
WiFi.mode(WIFI_STA)andWiFi.disconnect()
FAQs: ESP32 WiFi Scan – Answers to Common Questions
1. What is ESP32 WiFi Scan and why is it important?
Answer:
The ESP32 WiFi scan is a process that lets your ESP32 board detect nearby WiFi networks. It provides key details like SSID, RSSI (signal strength), and encryption type. This feature is essential for IoT projects because it allows your device to:
- Automatically select and connect to the strongest WiFi network
- Display available networks on an OLED or other interface
- Troubleshoot network issues
- Build smart, autonomous devices that work in multiple environments
Secondary keywords included: esp32 wifi scanner, esp32 wifi scan example, esp32 wifi scan code
2. How do I scan WiFi networks using ESP32?
Answer:
Using the Arduino IDE, you can perform a WiFi scan with just a few lines of code:
#include "WiFi.h"
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
}
void loop() {
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++) {
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.println(" dBm)");
}
delay(5000);
}
This ESP32 WiFi scan example shows how to detect all nearby networks and their signal strength.
Secondary keywords: how to scan wifi esp32, esp32 wifi example, esp32 wifi scannetworks
3. Can I perform a WiFi scan while connected to a network?
Answer:
Yes! The ESP32 allows scanning while maintaining the current WiFi connection using:
WiFi.scanNetworks(false, true);
- The first parameter
falseclears old scan results - The second parameter
trueenables scanning while connected
This is ideal for projects where you want your ESP32 to stay online while detecting other networks.
Secondary keywords: esp32 wifi scan while connected, esp32 wifi scan and connect
4. How do I scan WiFi using MicroPython on ESP32?
Answer:
For those who prefer Micropython ESP32 WiFi scan, use this code:
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
for net in sta_if.scan():
ssid = net[0].decode('utf-8')
rssi = net[3]
print(f"SSID: {ssid}, RSSI: {rssi} dBm")
- Lightweight and ideal for IoT devices
- Provides SSID and signal strength for each network
Secondary keywords: micropython esp32 wifi scan, esp32 wifi scan code
5. Why is my ESP32 WiFi scan not working?
Answer:
Common reasons why ESP32 WiFi scan failed include:
- WiFi mode is not set correctly (
WiFi.mode(WIFI_STA)) - Previous network connections are cached—use
WiFi.disconnect() - Too frequent scanning without delay
- Board definitions in Arduino IDE are outdated
- Hardware or power issues
Tip: Always include a short delay after disconnecting before starting a scan.
Secondary keywords: esp32 wifi scan not working, esp32 wifi scan failed
6. How do I display scanned WiFi networks on OLED with ESP32?
Answer:
You can create an ESP32 WiFi scanner OLED project:
#include
#include "WiFi.h"
Adafruit_SSD1306 display(128, 64, &Wire, -1);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
}
void loop() {
int n = WiFi.scanNetworks();
display.clearDisplay();
for (int i = 0; i < n && i < 6; i++) {
display.setCursor(0, i*10);
display.print(WiFi.SSID(i));
display.print(" ");
display.print(WiFi.RSSI(i));
}
display.display();
delay(10000);
}
This setup shows the top networks along with their signal strength, perfect for IoT dashboards.
Secondary keywords: esp32 wifi scanner oled, esp32 wifi signal strength meter
7. What is an async WiFi scan on ESP32?
Answer:
ESP32 WiFi scan async allows your device to scan networks without blocking other code execution.
WiFi.scanNetworks(true);
trueenables asynchronous scanning- Useful for ESP32 projects with web servers or multiple tasks
Secondary keywords: esp32 wifi scan async, esp32 scan wifi networks and connect
8. Can ESP32 connect to the strongest WiFi automatically?
Answer:
Yes! You can scan all networks and connect to the one with the highest RSSI:
int n = WiFi.scanNetworks();
int strongest = -1;
int maxRSSI = -100;
for(int i=0; i maxRSSI){
maxRSSI = rssi;
strongest = i;
}
}
WiFi.begin(WiFi.SSID(strongest).c_str());
- Automatically selects the network with the best signal
- Great for roaming IoT devices
Secondary keywords: esp32 wifi scan and connect, esp32 scan wifi networks and connect
9. How can I measure WiFi signal strength with ESP32?
Answer:
RSSI (Received Signal Strength Indicator) gives signal quality:
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++) {
Serial.print(WiFi.SSID(i));
Serial.print(": ");
Serial.println(WiFi.RSSI(i));
}
- Values closer to 0 are stronger
- Can be used to create an ESP32 WiFi signal strength meter
Secondary keywords: esp32 wifi signal strength meter, esp32 wifi scannetworks
10. What should I do if ESP32 WiFi scan fails repeatedly?
Answer:
Try these fixes:
- Reset ESP32 and reconnect
- Update Arduino IDE and ESP32 board definitions
- Reduce scan frequency
- Call
WiFi.mode(WIFI_STA)andWiFi.disconnect()before scanning - Ensure correct voltage and stable power
Secondary keywords: esp32 wifi scan failed, esp32 wifi scan config
11. Can ESP32 scan hidden WiFi networks?
Answer:
Yes. Use the hidden parameter in scan:
WiFi.scanNetworks(false, true);
- Includes hidden networks in results
- Useful for advanced ESP32 WiFi scan config
Secondary keywords: esp32 wifi scan config, esp32 wifi scan async
12. How often should I perform WiFi scans on ESP32?
Answer:
- Avoid scanning every second; it may cause resets
- Recommended: every 5–10 seconds
- Async scans help maintain responsiveness while scanning
Secondary keywords: esp32 wifi scan, esp32 wifi scan while connected
13. Can ESP32 scan multiple times without rebooting?
Answer:
Yes, but you should:
- Use
WiFi.disconnect()before each scan - Add small delays between scans
- Use async scanning to prevent blocking
This prevents scan errors and ensures accurate ESP32 WiFi scan results.
14. Can I combine scanning and connecting in one project?
Answer:
Absolutely! Many IoT projects combine:
- Scan all networks
- Filter known SSIDs
- Connect automatically to the preferred network
String knownSSIDs[] = {"HomeWiFi","OfficeWiFi"};
String knownPasswords[] = {"pass123","office123"};
- Ideal for ESP32 devices that need ESP32 WiFi scan and connect
Mr. Raj Kumar is a highly experienced Technical Content Engineer with 7 years of dedicated expertise in the intricate field of embedded systems. At Embedded Prep, Raj is at the forefront of creating and curating high-quality technical content designed to educate and empower aspiring and seasoned professionals in the embedded domain.
Throughout his career, Raj has honed a unique skill set that bridges the gap between deep technical understanding and effective communication. His work encompasses a wide range of educational materials, including in-depth tutorials, practical guides, course modules, and insightful articles focused on embedded hardware and software solutions. He possesses a strong grasp of embedded architectures, microcontrollers, real-time operating systems (RTOS), firmware development, and various communication protocols relevant to the embedded industry.
Raj is adept at collaborating closely with subject matter experts, engineers, and instructional designers to ensure the accuracy, completeness, and pedagogical effectiveness of the content. His meticulous attention to detail and commitment to clarity are instrumental in transforming complex embedded concepts into easily digestible and engaging learning experiences. At Embedded Prep, he plays a crucial role in building a robust knowledge base that helps learners master the complexities of embedded technologies.













