📘 WiFi Connectivity Implementation
🎯 Lesson Objective
In this lesson, students will learn:
- How ESP32 connects to WiFi
- How to write WiFi connection code
- How to monitor connection status using Serial Monitor
- Basic troubleshooting of WiFi connection issues
By the end of this lesson, students will be able to connect ESP32 to the internet successfully.
🌐 Concept Introduction
ESP32 has built-in WiFi, which allows it to connect to a wireless network just like a smartphone.
Once connected, it can:
- Send and receive data
- Communicate with cloud platforms
- Control devices remotely
📡 WiFi Modes in ESP32
ESP32 supports two main modes:
- Station Mode (STA) → Connects to an existing WiFi network
- Access Point Mode (AP) → Creates its own WiFi network
👉 In this project, we use Station Mode
🔐 WiFi Credentials
To connect ESP32 to WiFi, we need:
- SSID → WiFi name
- Password → WiFi password
💻 ESP32 WiFi Connection Code
const char* ssid = “YourWiFiName”;
const char* password = “YourPassword”;
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi”);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“\nConnected to WiFi!”);
Serial.print(“IP Address: “);
Serial.println(WiFi.localIP());
}
void loop() {
}
🔍 Code Explanation
#include <WiFi.h>→ Enables WiFi functionalityWiFi.begin()→ Starts connectionWiFi.status()→ Checks connection statusWL_CONNECTED→ Confirms successful connectionWiFi.localIP()→ Displays IP address
🧪 Practical Activity
- Replace:
YourWiFiNameYourPassword
- Upload code to ESP32
- Open Serial Monitor
- Observe:
- Connecting…
- Connected message
- IP Address
🧠 Key Learning Concepts
- Wireless communication
- Device networking
- Real-time connection monitoring
- Debugging using Serial Monitor
⚠️ Common Issues & Solutions
| Problem | Solution |
|---|---|
| Not connecting | Check SSID & password |
| Continuous dots (…) | Weak signal or wrong credentials |
| ESP32 restarting | Power supply issue |
| No output in Serial Monitor | Check baud rate (9600) |
🔧 Troubleshooting Tips
- Keep ESP32 close to WiFi router
- Use mobile hotspot if router fails
- Restart ESP32 and router
- Verify correct board selection in IDE
📝 Lesson Summary
In this lesson, students learned how to connect ESP32 to a WiFi network using programming. They also understood how to monitor and debug the connection using the Serial Monitor.
📌 Practice Task
- Connect ESP32 to a different WiFi network
- Note the IP address
- Try disconnecting WiFi and observe behavior