ESP8266 WiFi Module: Setup & Project Guide

ESP8266 is a Wi-Fi module suitable for IoT and home automation projects. It allows you to control inputs and outputs like you would with an Arduino series of boards, but with Wi-Fi. Therefore, it is well suited for home automation/IoT applications.

Comparing the ESP8266 with other Wi-Fi solutions on the market, it is an excellent choice for most “Internet of Things” projects. In this article, we’ll introduce the basic concepts of the ESP8266 board, it’s pinout, and programming examples.

Introduction to ESP8266

ESP8266 is a powerful and versatile Wi-Fi enabled microcontroller that has gained popularity in the world of electronics and IoT (Internet of Things). Developed by Espressif Systems, the ESP8266 offers a cost-effective solution for connecting devices to the internet and enabling them to communicate with each other. It features a built-in Wi-Fi module, a powerful processor, and GPIO pins for connecting external components. The ESP8266 can be programmed using various programming languages, making it accessible to both beginners and experienced developers. Its low power consumption and compact size make it ideal for a wide range of applications, including home automation, wireless sensor networks, and smart devices. For example, the ESP8266 can be used to create a smart thermostat that allows users to control the temperature of their homes remotely.

ESP8266 Pinout

ESP8266 Pinout
ESP8266 Pinout

In the pin diagram, some pins have other uses besides GPIO. For example, the D1 pin is not only GPIO5, but also an SCL interface, which can be connected to the corresponding SCL pin of the LCD screen.

The following table shows the correspondence between the labels on the onboard identification and GPIO numbers, and which pins are best used in projects, and which pins require caution. Pins highlighted in green are ready for use. Those highlighted in yellow can be used, but require attention as they may have unexpected behavior, mainly at startup. Pins highlighted in red are not recommended for use as inputs or outputs.

Board labelGPIOInputOutputNotes
D0GPIO16Digital; no GPIO interrupt in ESP8266 Arduino coreDigital; software PWM in Arduino coreFor deep-sleep wake, connect GPIO16 to RST; check board wiring.
D1GPIO5DigitalDigitalCommon Arduino-core I2C clock assignment; configurable in software.
D2GPIO4DigitalDigitalCommon Arduino-core I2C data assignment; configurable in software.
D3GPIO0Keep HIGH at reset for flash bootDigital after bootLOW at reset selects UART download; check the board FLASH-button wiring.
D4GPIO2Keep HIGH at resetDigital after bootLED connection depends on the board; do not tie GPIO2 directly to VCC.
D5GPIO14DigitalDigitalHSPI clock (SCLK) when assigned to SPI.
D6GPIO12DigitalDigitalHSPI data input (MISO) when assigned to SPI.
D7GPIO13DigitalDigitalHSPI data output (MOSI) when assigned to SPI.
D8GPIO15Keep LOW at resetDigital after bootHSPI chip select (CS); avoid an external pull-up during reset.
RXGPIO3UART0 RX or digital inputDigital if not used by UARTMay share the USB-UART bridge; not a boot-mode strap pin.
TXGPIO1Digital if not used by UARTUART0 TX or digital outputBoot messages appear here; not a boot-mode strap pin.
A0ADC0Analog inputNot availableChip ADC range is 0–1.0 V; the board A0 divider may change the allowed range. Check its schematic.

How to Connect WiFi Module to Microcontroller Hardware Safely

When connecting an ESP8266 Wi-Fi module to a microcontroller or Arduino-class board, treat power, logic levels and boot straps as separate design checks. Many apparent UART or firmware faults are actually supply dips or an invalid startup state. Confirm the exact module schematic because development boards may already include regulators and pull resistors.

  • Provide a stable 3.3 V rail: size the regulator and wiring for Wi-Fi current bursts, commonly reserving at least 500 mA of transient capability, with local bulk and high-frequency decoupling at the module.
  • Protect the logic pins: use 3.3 V-compatible signals and level-shift a 5 V host output before it reaches the ESP8266 input; connect the grounds at a low-impedance reference.
  • Wire the UART correctly: cross host TX to module RX and host RX to module TX, choose a known baud rate, and avoid loading the serial pins with LEDs or strong pull networks.
  • Set the boot straps: for common ESP-12-class hardware, hold EN high, GPIO2 high and GPIO15 low; keep GPIO0 high for normal boot and low during reset for flashing.
  • Bring up in stages: verify the 3.3 V rail and reset waveform, capture the boot log, identify whether AT firmware or custom firmware is installed, then test one command or packet before adding sensors.

How to Program ESP8266 with Arduino IDE?

There are many ways to program ESP8266:

  1. Use Arduino IDE to develop, follow the development style of Arduino, easy to use;
  2. Use ESP8266 official SDK development;
  3. Use MicroPython to develop, follow the programming style of Python (this method needs to burn a special firmware for the board first);

Here we choose the first one, because Arduino programming is simple and easy to operate.

Step 1: Install the Arduino IDE

Download IDE from Arduino official website: https://www.arduino.cc/en/software. The version I am using now is Arduino IDE 1.8.3. (Noted that the latest version of Arduino IDE 2.1.1 cannot install the ESP8266 resource package online.)

Install Arduino IDE 1.8.3
Install Arduino IDE 1.8.3

Step 2: Install the ESP8266 Package

Because the Arduino IDE is used for the Arduino development board by default, there are only relevant development resources for the Arduino development board by default. To use ESP8266 in Arduino IDE, we need to manually install the ESP8266 development package. There are two installation methods: online installation and offline package installation, here we choose the first one.

First, find the “File -> Preferences” in the Arduino IDE menu: 

Open Preferences in Arduino IDE
Open Preferences in Arduino IDE

And then, enter the below link in the “Additional Boards Manager URLs”:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Setting Additional boards manager URLs in Preferences
Setting Additional boards manager URLs in Preferences

Next, click to open the: Tools -> Board -> Board Manager.

Open Boards Manager in Arduino
Open Boards Manager in Arduino

In the field, input and search “esp8266”, you will see an esp8266 package, click “Install” to start online installation.

Search and Install the ESP8266 Board
Search and Install the ESP8266 Board
Installing ESP8266 packages
Installing ESP8266 packages

After the installation is complete, you can find all resources about the esp8266 board in the “Tools->Board” menu.

ESP8266 Boards Resource (3.1.2 Version)
ESP8266 Boards Resource (3.1.2 Version)

Step 3: ESP8266 Programming

Here we write a simple network connection test program for the ESP8266 board, the program code is as follows:

				
					void setup() {
  Serial.begin(9600);
  Serial.println("esp8266 test");
  initWiFi();

}

void loop() {
  Serial.println("hello esp8266");
  delay(1000);

}

#include <ESP8266WiFi.h>

constchar ssid[] = "xxxxx";      //WiFi Name
constchar pass[] = "xxxxx";       //WiFi Password

WiFiClient client;

//Initialize WIFI
void initWiFi()
{
   Serial.print("Connecting WiFi...");
   WiFi.mode(WIFI_STA); //Configure WIFI as Station mode
   WiFi.begin(ssid, pass); //Incoming ssid and password of WIFI hotspot
   while (WiFi.status() != WL_CONNECTED) //Waiting for successful connection
   {
     delay(500);
     Serial. print(".");
   }

   Serial.println("");
   Serial.println("WiFi connected");
   Serial.println("IP address: ");
   Serial.println(WiFi.localIP()); //print your own IP address
}
				
			

Notes:
The setup function is used for serial port initialization. For example, “Serial.begin(9600);” means that the initial baud rate of the serial port is 9600.

The loop function is similar to the while(1){} in the main function in the development of a single-chip microcomputer, where we can write program logic codes.

To use the WIFI function, you need to include the header file “ESP8266WiFi.h”.

The process of WIFI initialization includes 3 steps:

  1. Configure WIFI to Station mode, that is, our ESP8266 is used as a WIFI device;
  2. Pass in the ssid and password of the WIFI hotspot, so that ESP8266 can connect to the hotspot;
  3. Read the WIFI connection status and wait for the connection to be successful.

Select the model and serial port number of your ESP8266 development board:

Choose Board NodeMCU 1.0 (ESP-12E Module)
Choose Board NodeMCU 1.0 (ESP-12E Module)

Now, we can compile and burn the code into the ESP8266WiFi board.

Compile and Upload the code to ESP8266 WiFi Module
Compile and Upload the code to ESP8266 WiFi Module

Share to:

Scroll to Top

Instant Quote