Tag: ESP32 WiFi scan

  • ESP32 Connect to Router Tutorials: Master Complete Beginner-Friendly Guide

    Master ESP32 WiFi scan with this step-by-step guide. Learn to scan networks, connect to routers, fix connection issues, and build reliable IoT projects. Now!

    If you’ve just started working with the ESP32 and your first goal is to connect the ESP32 to a router, you’re in the right place. Think of this guide like you and I are sitting in a café, talking through each step so you understand not just what to do, but why things work the way they do.

    The ESP32 is powerful. It has built-in WiFi, Bluetooth, dual-core processing, and enough flexibility to handle IoT projects, home automation, robots, smart sensors, remote monitors, and even cameras. And the truth is: none of that matters unless the ESP32 connects to the internet correctly.

    By the end, you’ll have a practical understanding of how to connect ESP32 to WiFi router in multiple methods, troubleshoot common issues, and build real IoT setups.

    Let’s dive in.

    What Does ESP32 Connect to Router Actually Mean?

    When you tell the ESP32 to connect to a router, you’re doing two simple things:

    1. Giving the ESP32 the WiFi name (SSID)
    2. Giving it the password

    If everything goes well, the router assigns an ESP32 IP address, and the ESP32 becomes a device on your local network.

    Once connected, you can:

    • Access ESP32 web servers
    • Send data to Home Assistant
    • Connect ESP32 to Raspberry Pi
    • Use ESP32 as an internet-connected IoT device
    • Stream video if you’re connecting a camera to ESP32
    • Build ESP32 mesh network setups
    • Connect two ESP32 boards together

    Basically, the router becomes your bridge to the world.

    Requirements to Connect ESP32 to WiFi Router

    Before running any code, you need:

    • ESP32 DevKit, ESP32-C3, or ESP32-S3
    • Arduino IDE or MicroPython
    • A WiFi router (2.4 GHz — note this!)
    • Power via USB
    • Stable SSID and password

    Important:
    Most beginners face the “ESP32 not connecting to WiFi” error because the ESP32 does not support 5 GHz networks. Only 2.4 GHz works.

    ESP32 Connect to Router – Arduino Example

    This is the simplest ESP32 Arduino connect to WiFi code you’ll ever use.

    #include <WiFi.h>
    
    const char* ssid = "Your_WiFi_Name";
    const char* password = "Your_WiFi_Password";
    
    void setup() {
      Serial.begin(115200);
      WiFi.begin(ssid, password);
    
      Serial.println("Connecting...");
      
      while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.print(".");
      }
    
      Serial.println("\nConnected to router!");
      Serial.print("ESP32 IP address: ");
      Serial.println(WiFi.localIP());
    }
    
    void loop() {}
    

    What this does:

    You now have a working connection.

    Understanding ESP32 WiFi Events

    ESP32 is smart. It sends events whenever something happens:

    EventMeaning
    SYSTEM_EVENT_STA_CONNECTEDESP32 connected to router
    SYSTEM_EVENT_STA_DISCONNECTEDESP32 lost WiFi
    SYSTEM_EVENT_STA_GOT_IPRouter gave ESP32 IP address
    SYSTEM_EVENT_STA_LOST_IPESP32 lost its IP

    Handling WiFi events helps you build reliable systems.

    Example:

    WiFi.onEvent(WiFiEvent);
    
    void WiFiEvent(WiFiEvent_t event) {
      switch(event) {
        case SYSTEM_EVENT_STA_CONNECTED:
          Serial.println("Connected to WiFi");
          break;
    
        case SYSTEM_EVENT_STA_GOT_IP:
          Serial.println("Got IP:");
          Serial.println(WiFi.localIP());
          break;
    
        case SYSTEM_EVENT_STA_DISCONNECTED:
          Serial.println("Disconnected. Trying to reconnect...");
          WiFi.begin(ssid, password);
          break;
      }
    }
    

    This kind of setup helps avoid random disconnections.

    ESP32 Connect to Router – MicroPython Example

    If you prefer MicroPython, here’s how to connect ESP32 to WiFi MicroPython:

    import network
    import time
    
    ssid = "Your_WiFi_Name"
    password = "Your_WiFi_Password"
    
    wifi = network.WLAN(network.STA_IF)
    wifi.active(True)
    wifi.connect(ssid, password)
    
    print("Connecting...")
    while not wifi.isconnected():
        time.sleep(1)
        print(".")
    
    print("Connected!")
    print("ESP32 IP address:", wifi.ifconfig()[0])
    

    ESP32 Not Connecting to Router? (FIXED)

    This is the most searched problem:

    1. ESP32 not connecting to router

    2. ESP32 not connecting to WiFi

    Here are real causes and fixes:

    1. Your router is 5 GHz

    ESP32 connects only to 2.4 GHz, not 5 GHz.

    2. Wrong password

    Double-check uppercase, lowercase, and symbols.

    3. Special characters in SSID

    Try renaming your WiFi to something simple.

    4. Weak WiFi signal

    Bring the ESP32 closer to the router.

    5. MAC filtering enabled

    Turn off MAC filtering in router settings.

    6. Hidden SSID

    Enable SSID broadcast or manually enter details.

    7. Power issues

    A weak USB cable or port can cause random disconnects.

    ESP32 WiFi IP Address Explained

    Once ESP32 connects, you’ll get something like:

    192.168.1.92
    

    This is the ESP32 WiFi IP address.

    Your PC or phone can use this IP to:

    • Access ESP32 web server
    • Control LEDs
    • Read sensor values
    • Integrate into Home Assistant

    You can also set a static ESP32 IP address:

    WiFi.config(local_IP, gateway, subnet);
    

    How to Connect Camera to ESP32

    If you are connecting a camera to ESP32, you’ll most likely use:

    • ESP32-CAM
    • OV2640 camera module

    Once the camera boots, it connects to the router and provides a streaming link like:

    http://192.168.1.77
    

    You can open this in any browser.

    ESP32 as a Router (SoftAP Example)

    ESP32 can also act as a WiFi router itself.

    WiFi.softAP("ESP32_Router", "12345678");
    

    Now your phone or laptop can connect to the ESP32.

    This is used when:

    • No home router is available
    • You want to control ESP32 locally
    • You’re connecting two ESP32 boards

    Connecting Two ESP32 Boards Together

    You can connect ESP32 boards using:

    1. WiFi (station to station)

    2. ESP32 mesh network example

    3. Bluetooth

    4. UART wired communication

    The simplest way is soft AP + STA mode.

    ESP32 Connect to Raspberry Pi

    You can connect ESP32 to Raspberry Pi in 3 ways:

    Via router (recommended)

    Both connect to same WiFi.

    Direct WiFi (ESP32 as router)

    ESP32 softAP → Pi connects to ESP32.

    Serial communication

    UART between GPIO pins.

    Most people use the router method so the Pi can also connect ESP32 to the internet.

    ESP32 Connect to Arduino Uno

    You can connect ESP32 and Arduino Uno using multiple methods depending on your project:

    • Serial communication (RX/TX)
    • I2C
    • WiFi communication
    • Sending ESP32 data to the Uno to control sensors or motors

    If you want a deeper explanation with visuals, I’ve also covered this in my WiFi guide here: Master ESP32 WiFi Scan Tutorials

    Connect ESP32 to PC

    When ESP32 connects to a router, your PC can:

    • Open ESP32 web server
    • Read sensor data
    • Control GPIO pins
    • Flash firmware

    How to Connect ESP32 to Home Assistant

    Home Assistant → ESP32 integration is simple:

    • Use ESPHome
    • Or use MQTT
    • Or REST API

    ESP32 connects to your router, then Home Assistant reads data via local network.

    ESP32-C3 WiFi and ESP32-S3 Ethernet Notes

    ESP32-C3 WiFi

    Supports WiFi 2.4 GHz
    Low power
    Great for battery projects

    ESP32-S3 Ethernet

    Some S3 boards have Ethernet PHY
    Great for stable wired IoT
    Zero wireless drops

    ESP32 Mesh Network Example

    A mesh network means multiple ESP32 boards communicate without a central router.

    Perfect for:

    • Farms
    • Large buildings
    • Outdoor sensors
    • Long-range applications

    You can still connect one node to a router to access the internet.

    Troubleshooting – Quick Fix Table

    IssueFix
    ESP32 not connecting to routerUse 2.4 GHz
    ESP32 not connecting to WiFiCheck password
    Got IP but no internetRestart router
    ESP32 disconnects randomlyChange power cable
    ESP32 WiFi slowAvoid crowded channels
    ESP32 IP address changesAssign static IP

    Final Thoughts

    Connecting ESP32 to a router is the first big step in IoT development. Once your ESP32 connects to WiFi reliably, you can build smart home systems, cloud dashboards, camera streams, ESP32 mesh network example setups, or even connect ESP32 to Raspberry Pi or Arduino Uno for complex automation projects.

    If you follow the examples in this tutorial, your ESP32 will connect to the router confidently every time.

    FAQ on ESP32 Connect to Router

    1. How do I connect ESP32 to a router for the first time?

    To connect the ESP32 to a router, you only need the WiFi name and password. In Arduino IDE, you call WiFi.begin(ssid, password); and the router assigns an ESP32 IP address when the connection succeeds. If you’re using MicroPython, you activate the network interface and connect using wifi.connect(ssid, password).

    Search intent covered: esp32 connect to router, esp32 connect to wifi, how to connect esp32 to wifi router.

    2. Why is my ESP32 not connecting to router or WiFi?

    This is the most common beginner issue. The ESP32 connects only to 2.4 GHz WiFi, not 5 GHz. Wrong password, hidden SSID, weak signal, and MAC filtering are also common reasons. If you see “ESP32 not connecting to router,” first check whether the router is broadcasting 2.4 GHz WiFi.

    3. How can I find the ESP32 WiFi IP address once connected?

    Open the Serial Monitor after uploading your code. Arduino prints the ESP32 IP address using:

    Serial.println(WiFi.localIP());
    

    In MicroPython, use wifi.ifconfig()[0]. This IP allows your PC or phone to access ESP32 web pages, dashboards, and APIs.

    4. What is the simplest ESP32 Arduino connect to WiFi example?

    The easiest esp32 connect to wifi example is:

    WiFi.begin("YourSSID", "YourPassword");
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
    }
    

    It’s enough for small IoT projects like LED control, sensors, or data logging.

    5. How do I connect ESP32 to Home Assistant?

    The best way is using ESPHome. It automatically handles the connection when the ESP32 connects to your home router. You can also use MQTT, REST API, or a simple web server. If the ESP32 and Home Assistant are on the same WiFi network, communication is instant.

    6. Can I connect ESP32 to Raspberry Pi using WiFi?

    Yes. You can connect ESP32 to Raspberry Pi through the router (recommended), or make the ESP32 act as a WiFi access point and let the Raspberry Pi join it. Sending sensor data or commands becomes easy using HTTP, MQTT, or UDP.

    7. How do I connect ESP32 and Arduino Uno together?

    There are two ways:

    1. Wired (UART, I2C) – ESP32 sends sensor or WiFi data to Arduino Uno
    2. Wireless – both connect to the same router and communicate over WiFi

    This is helpful when you want WiFi features on the Uno.

    8. Can ESP32 work as a router or WiFi hotspot?

    Yes. ESP32 has a mode called SoftAP where it broadcasts its own WiFi network. This lets phones or other ESP32 boards connect directly. Many IoT projects use this for local configuration, dashboards, or controlling devices without a real router.

    9. How do I connect ESP32 to WiFi using MicroPython?

    MicroPython connection is simple:

    wifi = network.WLAN(network.STA_IF)
    wifi.active(True)
    wifi.connect("SSID", "Password")
    

    Keep looping until wifi.isconnected() returns true. Once connected, it gives you an ESP32 WiFi IP address.

    Search term included: connect esp32 to wifi micropython.

    10. Can ESP32 connect to the internet without a router?

    Yes. You have options:

    • Use ESP32 SoftAP mode and share internet from your mobile
    • Use ESP32 mesh network example (no router needed)
    • Use Ethernet with ESP32-S3 boards
    • Use a hotspot from your phone or laptop

    Without a router, you can still transfer data locally.

    11. Can I connect a camera to ESP32 for streaming?

    Yes. Using ESP32-CAM or modules like the OV2640. Once the ESP32 connects to your WiFi router, it streams video through a URL like:

    http://192.168.X.X
    

    You can view it on PC, mobile, Raspberry Pi, or Home Assistant.

    12. What is the difference between ESP32, ESP32-C3 WiFi, and ESP32-S3 Ethernet?

    • ESP32: Dual-core, strong performance, WiFi + Bluetooth.
    • ESP32-C3 WiFi: Low-power, single-core chip with WiFi 2.4 GHz support; best for battery devices.
    • ESP32-S3 Ethernet: Some S3 boards support Ethernet PHY, meaning you can connect wired networks when WiFi is unstable.

    13. How do I fix slow or unstable WiFi when connecting ESP32 to router?

    Here are practical fixes:

    • Keep ESP32 away from heavy power cables
    • Reduce distance from router
    • Ensure router is using channel 1, 6, or 11
    • Use a high-quality USB cable
    • Avoid using metal enclosures
    • Assign a static ESP32 IP address
    • Restart router weekly

    This eliminates the most common “slow esp32 wifi” issues.

  • Master ESP32 WiFi Scan Tutorials: A Beginner-Friendly Guide

    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.

    ESP32 WiFi Scan
    Learn ESP32 WiFi scan step by step. Beginner-friendly guide on scanning networks, connecting ESP32 to WiFi, fixing errors, and building smart IoT projects.

    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:

    1. Automated Connections: Your ESP32 can automatically find and connect to a preferred network without hardcoding SSID and password.
    2. Network Selection: If multiple networks are available, your ESP32 can choose the one with the strongest signal.
    3. Debugging: When your ESP32 fails to connect, scanning helps you identify network issues.
    4. 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 <Wire.h>
    #include <Adafruit_SSD1306.h>
    #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 <WiFi.h>
    #include <ESPAsyncWebServer.h>
    
    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:

    FeatureFunction
    Basic ScanWiFi.scanNetworks()
    Scan while connectedWiFi.scanNetworks(false, true)
    Async scanWiFi.scanNetworks(true)
    Scan + connect strongestCompare RSSI values
    Display on OLEDAdafruit_SSD1306 library
    MicroPython scannetwork.WLAN(network.STA_IF).scan()

    Best Practices for ESP32 WiFi Scan: Tips for Reliable Scanning and Connectivity

    1. Always disconnect before scanning to avoid stale results.
    2. Avoid scanning too frequently; ESP32 may reset if overworked.
    3. Use async scans for multitasking projects.
    4. Limit displayed networks if using OLED.
    5. 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) and WiFi.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 false clears old scan results
    • The second parameter true enables 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:

    1. WiFi mode is not set correctly (WiFi.mode(WIFI_STA))
    2. Previous network connections are cached—use WiFi.disconnect()
    3. Too frequent scanning without delay
    4. Board definitions in Arduino IDE are outdated
    5. 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 <Adafruit_SSD1306.h>
    #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);
    
    • true enables 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<n; i++){
        int rssi = WiFi.RSSI(i);
        if(rssi > 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:

    1. Reset ESP32 and reconnect
    2. Update Arduino IDE and ESP32 board definitions
    3. Reduce scan frequency
    4. Call WiFi.mode(WIFI_STA) and WiFi.disconnect() before scanning
    5. 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:

    1. Scan all networks
    2. Filter known SSIDs
    3. 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