Are you having issues with ESP32 won’t connect to WiFi? We have proven solutions that will help you resolve this problem.
The ESP32 is a low-cost SoC that comes with connectivity options allowing you to create systems on top of your current setup.
Our solutions will help you resolve a common WiFi issue that nearly all users can encounter.
Let’s get to solving your issues.
To connect your ESP32 to WiFi, you want to make sure that your system can detect your network. Your ESP32 may also be set to a different mode so make sure to switch it to Station Mode. You also want to connect your system to 2.4 GHz WiFi since the ESP32 is unable to connect to the 5 GHz frequency.
Before we move on to the full fix guide, we can take a closer look at the possible causes of this problem.
Why ESP32 Won’t Stay Connected to WiFi
When your ESP32 system doesn’t connect to your WiFi network, there are a few sources to focus on.
One, in particular, is that you’re not using the proper WiFi library in your code. Your router is also too far away for your system’s wireless network module to pick up.
Here are the possible issues that you’re going to face with your ESP32:
1. WiFi Library Is Not Loaded
To configure your ESP32, you will need to do some coding. You need to reference certain code libraries so you can use different commands.
You may have forgotten to use the WiFi library, and this can cause connectivity problems.
2. Router Too Far Away
Just like other devices, your ESP32 needs to be within a certain range of your router. It won’t connect properly if it’s too far away and can often disconnect.
3. ESP32 on a Different Connection Mode
You can set your ESP32’s WiFi module as an access point, a client, or both. Setting it to a different mode can cause WiFi issues.
4. 5G WiFi is Incompatible
There are versions of the ESP32 that do not work well with 5G WiFi. Make sure your network is using the usual 2.4 GHz frequency.
These are all the issues you’re likely to face with your ESP32’s WiFi woes.
Now that you have a better understanding, we can now proceed to the complete troubleshooting guide!
How to Fix ESP32 Won’t Connect to WiFi
The first thing you can do to fix this issue your WiFi issues is to reboot your ESP32.
You can do it by cutting the power, so if it’s connected to your computer via the USB port, simply pull it out to shut it down.
Wait for a few seconds before plugging it back in and checking if it reconnects to the network on its own.
You can also hold down the Boot button and wait for your system to shut down.
In case it doesn’t, and you’re having a hard time getting it to connect to WiFi, here are the other solutions you can try:
Solution #1: Include the WiFi.h Library in Your Code
The very first fix that you should consider is making sure that you include the ESP32’s WiFi library.
This is the only way to use WiFi functionalities in your system. Now, you don’t have to worry if you need to upload an external file onto your device.
As long as you have installed ESP32, you should have it ready for use.
Here’s how to include WiFi.h:
- Install ESP32 by going to Arduino Boards Manager.
- Search for ESP32.
- Press the Install button.
- Add #include <WiFi.h> in your code.
Note: Scan your network and see if your ESP32 can detect your active networks.
Solution #2: Reconnect to the WiFi Network
After including the right libraries into your ESP32 sketches, you will want to attempt to reconnect to your WiFi network.
Reconnecting on the ESP32 is a bit different than most of your devices. There are a few steps that you need to do before you can successfully detect and connect to your network.
You want to make sure that everything is in order and that your system can see the network you want to connect to.
Here are the steps on how to successfully connect your ESP32 to WiFi:
- In your IDE, go to File, then Examples.
- Select WiFi, then WiFiScan.
- Check for available networks that your system can detect.
- Connect to your WiFi network using the initWiFi() function.
Note: You can also know your connection's signal strength by using the RSSI function.
Solution #3: Put Your ESP32 Into Flash or Upload Mode
The next thing that you need to do is to flash your system.
If you’re having connection issues, your current sketch or code is not properly uploaded to your ESP32, and your changes are not properly loaded into your device.
This step is more like a soft reset for your ESP32 board and ensures that future changes are reflected in your system.
Here’s how to put your ESP32 into flash or upload mode:
- Press and hold the Boot button on the ESP32 board.
- Click on the Upload button in the Arduino IDE on your computer.
- Wait for the Connecting message to appear on the terminal window.
- Release the Boot button.
- The Done Uploading message should appear.
Tip: Your new sketch with changes to your connections is now loaded to the board, and it will start to connect to your WiFi.
Solution #4: Set Your ESP32 to Station Mode
Your ESP32’s WiFi module can be configured to different modes.
It can broadcast WiFi signals as an access point, be it a device that connects to a WiFi source or even both.
If your ESP32 doesn’t connect to your WiFi, you can check if it’s set to the Access Point Mode.
If this is the case, you’ll want to set it back to Station Mode so it can receive the signal from your router.
Here’s how to set your ESP32 to Station Mode:
- Use WiFi.mode(WIFI_STA) to set your ESP32 to Station Mode.
- Know the SSID and password of your network.
- Use the initWiFi() function to connect to your network.
- Replace ssid with your network’s SSID.
- Replace password with your network’s WiFi password.
Pro Tip: You can also set your ESP32 as a station and access point, adding versatility.
Solution #5: Set a Static IP on Your ESP32
If none of these solutions work so far, you’ll want to explore setting your ESP32 with a static IP. Connectivity issues can cause your device to stop connecting to your WiFi.
Your system cannot properly connect to your router’s DHCP servers, so it’s not assigned an IP address.
You can set your ESP32 with a static IP address to remedy this. This way, your system has a more permanent IP address, which makes it easier for you whenever you connect it with other devices.
Here’s how to set a static IP address on your ESP32:
- Use the WiFi.config() function to set a static IP address for your system.
- Change the value in local_IP by putting your IP address.
- Change the value under gateway to the IP address of your router.
- Call the WiFi.config() function in setup() to assign your IP addresses.
Tip: You can also change your DNS addresses for better connectivity.
Solution #6: Enable 2.4G WiFi on Your Router:
ESP32 systems are low-cost, barebones types of devices with minimal features and functionalities.
Yes, they’re going to have WiFi and Bluetooth capabilities, but they’re not going to be using top of the line hardware for those.
Your ESP32 will not have 5G WiFi available.
If your system doesn’t readily connect to your wireless network, you want to make sure that the 2.4 GHz frequency on your router is switched on.
Here’s how to enable 2.4G WiFi on your router:
- Access your router’s dashboard by typing its IP address on your browser.
- Log in using your router’s username and password.
- Navigate to WiFi, then Advanced.
- Turn on your router’s dual-band features.
- Alternatively, you can switch on 2.4 GHz.
Note: You can also disable your router’s 5G WiFi to ensure that it’s only broadcasting in 2.4 GHz.
After going through these solutions, you can be sure that you’ll be able to connect your ESP32 to your WiFi in no time.
If you continue to experience issues with your system, you can always contact Espressif System’s customer support team so they can guide you on the next steps.
Read Next: What is the Cheapest Way to Keep a Phone Number?
Bottom Line
Now that you know the fix to your ESP32 won’t connect to WiFi problem, you will be able to resolve the error.
As long as you follow the steps carefully, fixing your ESP32 won’t take too much of your time and effort.
Finn Wheatley holds a Master’s Degree in Computer Science from UCL, London. He helped small data science consultancy firms, helping large corporations to grow their data capabilities, deploy advanced machine learning-based analytics and troubleshoot tech-related issues. Check out more about him here.