Connecting To WiFi

Use the sketch here to connect your ESP8266 module to your local WiFi network. The sketch writes messages to the serial monitor of your IDE - to access this, in the IDE go to Tools->Serial Monitor.

Copy and paste the sketch into the IDE and then:

  1. Replace the asterisks in the definitions of ssid and password below with your network's name (SSID) and password
  2. The speed of the serial connection is set as 115200bps in the sketch. Make sure the speed in your serial monitor is the same. When the serial monitor is open, you can set the speed in the drop-down menu in the bottom right corner.

This sketch presumes that your network is using DHCP to lease IP addresses, if not, there will be a webpage soon that explains how to assign a static IP address and other network settings.

* connect-to-wifi     V1.0 01-Aug-2018 JST Lawrence.                           *
*                                                                              *
* Purpose: connects to a wireless network.                                     *
*                                                                              *
* Output: display connection progress and IP address once connected.           *
*                                                                              *

#include "ESP8266WiFi.h"

const char* ssid="**********";    // Put your SSID here
const char* password="**********";  // Put your password here

void setup(void)

// Connect to WiFi
  WiFi.begin(ssid, password);
  Serial.println("Trying to connect");

// Loop until we obtain a connection
  while (WiFi.status()!=WL_CONNECTED) 

// New line
  Serial.println("WiFi connection Successful");
  Serial.print("IP address : ");


void loop() 
// Put your code here

Serial monitor - WiFi connecting You need to compile the sketch and upload it to the ESP8266. When it finishes uploading, open your serial monitor and wait for a successful connection. You'll see something similar to that below. Asterisks are printed every 0.5s to show that a connection is still be attempted.

There is another sketch that does the same thing but also blinks the onboard LED to indicate the connection status if you are unable to watch the serial monitor. When the connection is successful, the LED stays on.