๐ 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