๐Ÿ“˜ 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

ย 
#include <WiFi.h>

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 functionality
  • WiFi.begin() โ†’ Starts connection
  • WiFi.status() โ†’ Checks connection status
  • WL_CONNECTED โ†’ Confirms successful connection
  • WiFi.localIP() โ†’ Displays IP address

๐Ÿงช Practical Activity

  1. Replace:
    • YourWiFiName
    • YourPassword
  2. Upload code to ESP32
  3. Open Serial Monitor
  4. 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