Course Content
IoT Engineering Course using ESP32 Wifi Robots

📘 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
Scroll to Top