Esp32 Connect To Wifi

About the project

This tutorial is about how to get started using the WiFi function of the ESP32. You can choose specific WiFi network and connect to it. You can monitor the connection status via serial monitor. All the tests performed here using ESP32 NodeMCU module.

Project info

Difficulty: Easy

Platforms: ArduinoBlynkEspruinoEverything ESP

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

ESP32 WiFi-BT-BLE MCU Module / ESP-WROOM-32 ESP32 WiFi-BT-BLE MCU Module / ESP-WROOM-32 x 1
Half-size Breadboard Half-size Breadboard x 1

Software apps and online services

arduino IDE arduino IDE You can download this software from this site. https://www.arduino.cc/en/software

Story

This tutorial about how to setup your ESP32 NodeMCU to connect with you home wifi. 

How It's work.

Start by including the necessary libraries. 

  1. #include "WiFi.h"

In the following variables, define your access point network credentials:

  1. const char* ssid = "yourNetworkName";
  2. const char* password = "yourNetworkPass";

For example, your wireless SSID is "KakiGodek-WiFi" and your password is "kakigodek123". So you need to replace "yourNetworkName" to "KakiGodek-WiFi" for the SSID, and "yourNetworkPass" to "kakigodek123" for the password.

In the setup(), initialize the Serial Monitor for demonstration purposes.

  1. Serial.begin(115200);

Set your ESP32 as an access point with the SSID name and password defined earlier.

  1. WiFi.begin(ssid, password);

Then we do a while loop until the connection is establish. We can call the status method on the WiFi object and wait for the result to match the  WL_CONNECTED enum. We put a small delay to avoid a constant poll.

  1. while (WiFi.status() != WL_CONNECTED) {
  2. delay(500);
  3. Serial.println("Connecting to WiFi..");
  4. }

When ESP32 successful connected to you WiFi, you can see the result via serial monitor

  1. Serial.println("Connected to the WiFi network");
  2. // Print local IP address and start web server
  3. Serial.println("");
  4. Serial.println("WiFi connected.");
  5. Serial.println("IP address: ");
  6. Serial.println(WiFi.localIP());

Watch the Video Demonstration

Code

Basic : ESP32 NodeMCU connect to WiFi

Credits

Photo of kakigodek

kakigodek

Like to explore and learn something new in my life and the host of the YouTube channel kakigodek

   

Leave your feedback...