Connect ESP8266 NodeMCU to Wi-Fi Network

Connect ESP8266 NodeMCU to Wi-Fi Network

The ESP8266 can operate on station (STA) mode. It means that ESP8266 can connect to an existing Wi-Fi network. ESP8266 gets IP address from wireless router and can start to send or receive data from the Internet.

This tutorial provides example how to connect the ESP8266 NodeMCU development board to a Wi-Fi network.

Components

No.ComponentQuantity
1.ESP8266 NodeMCU + Micro USB cable1

Code

We define two constants which stores Wi-Fi network SSID and password. In the setup function we initialize serial communication at a baud rate of 9600. Wi-Fi connection is started by using WiFi.begin function. We can check connectivity status with WiFi.status function. It returns WL_CONNECTED status when ESP8266 NodeMCU successfully connected to a Wi-Fi network.

#include <ESP8266WiFi.h>

const char *WIFI_SSID = "YOUR WIFI NETWORK NAME";
const char *WIFI_PASSWORD = "YOUR WIFI PASSWORD";

void setup()
{
    Serial.begin(9600);

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("Connected");
}

void loop() {}

Leave a Comment

Cancel reply

Your email address will not be published.