Lesson objectives
The goal of this lesson is to introduce you to networking concepts related to IoT. When you finish the lesson, you will understand the importance of network connectivity in IoT devices and be able to connect to WiFi.
Introduction
In this lesson, we dive deeper into the world of IoT by learning how to connect the ESP32 microcontroller to a WiFi network. One of the most central features of IoT devices is their ability to send and receive data over the internet, enabling remote monitoring, control, and data analysis.
Establishing a WiFi connection is the first step toward getting your IoT device to interact with the outside world. It allows your ESP32 to send sensor data to cloud platforms, trigger alerts, or even host web servers that you can access through a browser on any device connected to the same network.
List of required components:
![]() |
AHT10 high-precision temperature and humidity sensor |
![]() |
TTGO T-Display ESP32 16MB with WiFi, Bluetooth and 1.1" color LCD screen |
![]() |
Dupont cables, 40 pcs |
WiFi connectivity in IoT
WiFi connectivity is a key feature in many IoT devices, as it enables wireless communication over long distances without physical cables. By connecting your ESP32 to a local WiFi network, your device can:
-
Communicate with web servers
-
Send data to cloud services
-
Receive commands remotely
-
Display real-time data through its own web interfaces
These capabilities make IoT so powerful — enabling remote monitoring, control, and automation.
Step 1: Preparing for WiFi connectivity
Before we look at the code, have the following ready:
-
Network details: You need the SSID (network name) and password for your WiFi network. Make sure it is a reliable network with internet access.
-
Updated libraries: Make sure your Arduino IDE is up to date and the
WiFi.hlibrary is included, as it usually is when working with the ESP32. This library contains all the functions needed for WiFi connectivity.
Step 2: Connect ESP32 to WiFi
Connecting the ESP32 to WiFi is quite straightforward thanks to the built-in WiFi.h library. Here is the basic code:
#include <WiFi.h> // Udskift med dine netværksoplysninger const char* ssid = "Your_SSID"; // Dit netværksnavn const char* password = "Your_Password"; // Din adgangskode void setup() { Serial.begin(115200); delay(100); // Tilslut WiFi WiFi.begin(ssid, password); Serial.print("Tilslutter WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(); Serial.println("Tilsluttet WiFi!"); Serial.print("IP-adresse: "); Serial.println(WiFi.localIP()); } void loop() { // Her kan du tilføje funktioner, der skal køre mens WiFi er tilsluttet }
Code explanation:
-
Library:
WiFi.his included to use the WiFi connection functions. -
Network details:
ssidandpasswordare your WiFi credentials — remember to change them to your own. -
Connection:
WiFi.begin()starts the connection. -
Connection loop:
whileloop ensures that the ESP32 keeps trying to connect until it succeeds. -
IP address: Once connected, the IP address is displayed in the Serial Monitor.
Step 3: Test the WiFi connection
To make sure your ESP32 is connected correctly:
-
Upload the code to the ESP32 using Arduino IDE
-
Open the Serial Monitor (Ctrl + Shift + M or via the Tools > Serial Monitor menu)
-
Set the baud rate to 115200
-
You will see dots being printed while the ESP32 tries to connect — followed by "Tilsluttet WiFi!" and the IP address once it succeeds.
Troubleshooting:
-
Incorrect details: Check that the SSID and password are correct
-
Weak signal: Make sure the ESP32 is within range of the router
-
Network security: Some networks may have restrictions; try another network if necessary
Step 4: What happens once connected?
Once the ESP32 is connected to WiFi, it becomes part of your local network. This means it can:
-
Communicate with other devices on the network
-
Send data to the internet
-
Host web servers that you can access in your browser
In the next lesson, we build on this and create a simple web server on the ESP32 that displays real-time sensor data.
Conclusion
In this lesson, you learned the basics of WiFi connectivity with the ESP32 and connected to a network. This is an important step in any IoT project because it opens the door to data exchange, remote control, and interactive applications.
Next step? We create a web server on the ESP32 and display sensor values directly in the browser.
You are well on your way — great work!
About the measurements: The station in this series measures temperature and relative humidity using the AHT10. These are indoor climate readings, not direct measurements of CO2, VOCs, or particles. The series name “air quality monitoring” should be understood with this limitation.


