ESP32 WiFi Scan For Networks Example (Arduino IDE)

In this tutorial, you’ll learn how to implement an ESP32 WiFi Scanner with Arduino IDE. The ESP32 WiFi Scan Example application is your first step in exploring the WiFi capabilities of the ESP32. As it gives you all available WiFi networks nearby and makes sure that the ESP32 WiFi is working properly.

Before proceeding with this tutorial, you should have installed the ESP32 Arduino Core in your Arduino IDE to be able to compile and build projects for ESP32 in Arduino IDE. Follow the tutorial below to get started if you haven’t done that already.

If you’re just starting with ESP32, it’s highly recommended to begin with the following tutorial to kickstart your journey with ESP32 microcontrollers. Then, go to the second link which directs you to the main page for ESP32 Tutorials Series, where you’ll find all ESP32 tutorials ordered and categorized in a logical way that guarantees you systematic progress in learning ESP32 programming and IoT.

Table of Contents

  1. ESP32 WiFi Scan Example
  2. ESP32 WiFi Scan Not Working
  3. Concluding Remarks

ESP32 WiFi Scan Example

To scan for the available WiFi networks nearby your ESP32, you can simply use the ESP32 WiFiScan example sketch in your Arduino IDE. Open File > Examples > WiFi > WiFiScan sketch.

Here is the full code listing of this example:

This example is particularly useful when you try to connect to a nearby network but keeps failing. This WiFi scanner example will show you the signal strength of each WiFi network within the ESP32 range. The RSSI (Received Signal Strength Indicator) is what you’re looking for if you’d like to know the signal strength of each nearby network.

The function WiFi.scanNetworks() is used to handle the core logic of WiFi scanning and it returns the total number of networks found.

At this point, you’ll have the number of found networks nearby and you can access any of the following parameters of each network.

  • SSID
  • RSSI
  • Channel
  • EncryptionType

To get & print the SSID of any found network in the list, call the following function WiFi.SSID(i) and pass to it the index of the found network.

To get and print the RSSI (Received Signal Strength Indicator), use the WiFi.RSSI(i) function as shown below.

Which gives you an estimated signal strength value for any surrounding network you’ve found while scanning.

To get & print the WiFi channel number for a found network use the WiFi.channel(i) function and pass to it the found network’s ID as shown below.

And lastly, you can get & print the WiFi encryption type of any found network using WiFi.encryptionType(i) function as shown below.

Where the possible options for WiFi network encryption type are the following:

  • WIFI_AUTH_OPEN
  • WIFI_AUTH_WEP
  • WIFI_AUTH_WPA_PSK
  • WIFI_AUTH_WPA2_PSK
  • WIFI_AUTH_WPA_WPA2_PSK
  • WIFI_AUTH_WPA2_ENTERPRISE
  • WIFI_AUTH_WPA3_PSK
  • WIFI_AUTH_WPA2_WPA3_PSK
  • WIFI_AUTH_WAPI_PSK

And this is the result of running the ESP32 WiFi Scanner sketch on my board.

ESP32-WiFi-Scanner-Arduino-Example-Result

And I can definitely confirm that my home router WiFi has the strongest signal as it’s in the next room, followed by my other router on another floor which has a bit weaker signal as we can expect. So we can conclude this topic and move to the next which is trying to connect to an existing WiFi network with ESP32.


ESP32 WiFi Scan Not Working

Sometimes the WiFi scan sketch doesn’t operate properly and this is because your board is going to draw a significant amount of current at startup which can be an issue if you’re not using a good power supply. So we can say that the potential causes of such an issue may be one or more of the following:

  • Poor-quality USB cable
  • Using long USB cables
  • Using a USB extender cable
  • The power supply can’t supply sufficient current
  • The USB port is not capable of delivering the required current

Try using a different power supply or use the external 3.3v or 5v input port if you can’t get it running on the power delivered by the USB port. I did run into a similar issue in the past and the reason turned out to be the USB extender cable was not coping with the current demand of the ESP32 board.

❕ Note

A very good indication that you’re facing a power supply or cable issue is having a brownout reset. Observe the Serial monitor and check the messages sent by the ESP32. Whenever your board runs into a brownout reset detection event, it’ll send you a message over the serial port.


Parts List

Here is the full components list for all parts that you’d need in order to perform the practical LABs mentioned here in this article and for the whole ESP32 series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.


Concluding Remarks

To conclude this tutorial, we’ll highlight the fact that the ESP32 WiFi Scanner application is just your first step with ESP32 WiFi in order to find the surrounding networks and make sure that the WiFi library and HW are working just as fine on your end. The next step is to try connecting to an existing WiFi network and this is what you’ll learn in the next tutorial.

If you’re just starting to learn about ESP32 WiFi, it’s highly recommended that you follow the tutorial below and keep it bookmarked in your browser. It is crafted specifically to help beginners with ESP32 WiFi to know everything about this huge topic and draw a clear roadmap for what to learn in a systematic way.

You can easily get overwhelmed when starting with ESP32 WiFi by the number of topics and libraries out there (e.g HTTP, TCP/IP, UDP, WebServers, AsyncWebServers, WebSocket, MQTT, ESP-NOW, etc…). There are too many libraries, modes, topologies, and protocols that make just getting started an even harder task than it should be. And the most reasonable question is where should I get started? The guide below is the perfect answer!

💡 Also Read
ESP32 WiFi Tutorial & Library Examples

This is the ultimate guide for ESP32 WiFi, if you’re just starting with ESP32 WiFi, you should definitely check it out. It’ll provide you with a clear roadmap for what to learn and in which order to fully understand everything about ESP32 WiFi.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?