Connecting the ESP8266 to WiFi is surprisingly simple once you have the board set up in Arduino IDE. Here is everything you need to get online in a few minutes.
Install the ESP8266 board in Arduino IDE
Open Arduino IDE, go to File → Preferences, and paste the following URL into the Additional Boards Manager URLs field:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Then go to Tools → Board → Boards Manager, search for esp8266, and install the package by ESP8266 Community.
Select your board
Go to Tools → Board and pick your variant. For NodeMCU choose NodeMCU 1.0 (ESP-12E Module). Make sure the correct port is selected under Tools → Port.
The code
Full source: github.com/viktoriabuilds/esp8266-wifi-tutorial
#include <ESP8266WiFi.h>
const char* ssid = "Your SSID";
const char* password = "Your Password";
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(115200);
Serial.println();
Serial.print("Wifi connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println();
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
digitalWrite(ledPin, HIGH);
Serial.println();
Serial.println("Wifi Connected Success!");
Serial.print("NodeMCU IP Address : ");
Serial.println(WiFi.localIP());
}
void loop() {
// your code here
}
Upload the sketch and open the Serial Monitor at 115200 baud. The ESP8266 will connect and print its local IP address. The LED on pin 13 will turn on once connected.
Next steps
Once connected you can make HTTP requests, serve a small web page, or send sensor data to a cloud API.