Contents
Introduction
The ESP32 microcontroller has built-in Wi-Fi, making it the perfect platform for IoT projects. In this guide, we cover every method to connect your ESP32 to Wi-Fi using the Arduino IDE.
ESP32 Wi-Fi Modes
- Station Mode (STA): ESP32 connects to your router as a client.
- Access Point Mode (AP): ESP32 creates its own hotspot.
- STA+AP Mode: Both simultaneously.
Project 1: Basic Wi-Fi Connection
#include <WiFi.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println("Connected! IP: " + WiFi.localIP().toString());
}
void loop() {
if (WiFi.status() != WL_CONNECTED) WiFi.reconnect();
delay(10000);
}
Project 2: Scan Nearby Networks
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100);
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++)
Serial.printf("%d: %s (%d dBm)\n", i+1, WiFi.SSID(i).c_str(), WiFi.RSSI(i));
}
void loop() {}
Troubleshooting Tips
- ESP32 only supports 2.4GHz networks, not 5GHz.
- RSSI below -80 dBm means weak signal — move closer to router.
- Getting 0.0.0.0? Restart your router or reduce DHCP clients.
Conclusion
Wi-Fi connectivity is the foundation of every ESP32 IoT project. Once connected, you can push data to cloud platforms, MQTT brokers, or host web servers directly from the chip!