ESP8266 Arduino tutorial – WiFi module complete review

ESP8266 Arduino WiFi module tutorial and review

Technology goes ahead exponentially with each year whether we do something or not. With the same speed engineers work hard to reduce the size of every electronic device or component and loose most of the wiring. If you look back 20 years ago a device was called portable if you could rise it in your arms and carry up. Today nothing is portable if it can’t fit in your pocket. Nowadays devices, either they are made for regular or industrial use, are based on wireless communication technology and the main reason is not to get rid of wires, but to be able to interconnect between them. Meanwhile buying a wireless device became natural for everyone and price for WiFi Ready equipment lowered with time passing. While you read this, a WiFi microchip has no more than 5mm length and can be powered with as low as 10 micro Amps during sleep period. In this article we are going to test one of the cheapest and easy to use WiFi development platform, the ESP8266 arduino compatible device.

Cheap WiFi solution for your first IoT project – ESP8266 Arduino compatible wifi module with 1Mb flash upgrade

ESP8266 Arduino compatible module iot internet of things

ESP8266 Wifi Module design

The ESP8266 arduino compatible module is a low-cost Wi-Fi chip with full TCP/IP capability, and the amazing thing is that this little board has a MCU (Micro Controller Unit) integrated which gives the possibility to control I/O digital pins via simple and almost pseudo-code like programming language. This device is produced by Shanghai-based Chinese manufacturer, Espressif Systems.

This chip was first time seen in August 2014, in ESP-01 version module, made by AI-Thinker, a third-party manufacturer. This little module allows the MCU to connect to WiFi network and create simple TCP/IP connections. His His very low price (1.7$ – 3.5$) and the incredible small size attracted many geeks and hackers to explore it and use it in a large variety of projects. Being a true success, Espressif produces now many versions having different dimensions and technical specifications. One of the successors is ESP32. You can find over the internet hundreds of projects and various implementations like home automation, data logging solutions, robotics, controlling things over the internet, even drones or copters.

ESP8266-01Technical specifications

  • 32-bit RISC CPU: Tensilica Xtensa LX106 running at 80 MHz **
  • 64 KiB of instruction RAM, 96 KiB of data RAM
  • External QSPI flash – 512 KiB to 4 MiB* (up to 16 MiB is supported)
  • IEEE 802.11 b/g/n Wi-Fi
  • Integrated TR switch, balun, LNA, power amplifier and matching network
  • WEP or WPA/WPA2 authentication, or open networks
  • 16 GPIO pins **
  • SPI, I²C,
  • I²S interfaces with DMA (sharing pins with GPIO)
  • UART on dedicated pins, plus a transmit-only UART can be enabled on GPIO2
  • 1 10-bit ADC

** CPU and flash clock speeds can be raised via overclocking on some devices and the 16 I/O are not available in all versions.

ESP8266 Arduino module comes with PCB trace antenna which seems to have a very good coverage (I saw a demonstration with more than 1km range!!!). Other version can have on-board ceramic antenna or an external connector which allows you to attach external WiFi antennas modules. ESP-01 has only 6 active pins, although the MCU can support up to 16 I/O. Board dimensions are 14.3 x 24.8 mm.

ESP8266 ESP-01 Arduino Module 1mb vs 0.5mbOver the internet i found that ESP8266 arduino module, version 01, is sold in two or more versions, which at first glance seem quite the same. After buying both of them i saw that there is a difference in size of the flash memory. You may encounter issues while flashing if you don’t make the proper settings according to board specifications.

Although the board default has 2 available GPIOs, you can do some workarounds and use other MCU available pins if you have the proper soldering tools. I managed to use GPIO 16 in order to wake up the device after DEEP SLEEP mode (explained later in SLEEP MODES).

Module pin description (pinout)ESP8266-01 PIN description pinout

Pins are arranged in two rows, having 4 on each row. Some models have pin description on the PCB, which make it simple. On the top row you can find following pins from the left to the right:

  1. GND (Ground from power supply)
  2. GPIO2 (Digital I/O programmable)
  3. GPIO0 (Digital I/O programmable, also used for BOOT modes)
  4. RX – UART Receiving channel

On the bottom (second row) you can find:

  1. TX – UART Transmitting channel
  2. CH_PD (enable/power down, must be pulled to 3.3v directly or via resistor)
  3. REST  – reset, must be pulled to 3.3v)
  4. VCC  -3.3v power supply

Power supply and current consumption

All esp8266 arduino compatible modules must be powered with DC current from any kind of source that can deliver stable 3.3V and at least 250mA. Also logic signal is rated at 3.3v and the RX channel should be protected by a 3.3v divisor step-down. You should be careful when using this module with Arduino or other boards which supplies 5v, because this module usually do not come with overpower protection and can be easily destroyed.

Here is the declared power consumption from Espressif:

ParametersTypicalUnit
Tx802.11b, CCK 11Mbps, P OUT=+17dBm 170 mA
Tx 802.11g, OFDM 54Mbps, P OUT =+15dBm 140 mA
Tx 802.11n, MCS7, P OUT =+13dBm 120 mA
Rx 802.11b, 1024 bytes packet length , -80dBm 50 mA
Rx 802.11g, 1024 bytes packet length, -70dBm 56 mA
Rx 802.11n, 1024 bytes packet length, -65dBm 56 mA
Modem-Sleep 15 mA
Light-Sleep 0.9 mA
Deep-Sleep 10 uA
Power Off 0.5 uA

If you are going to use ESP-01 in a project that is powered by batteries or by solar power it is mandatory to know everything about ESP8266 arduino Sleep modes. Current version offers 3 different sleep modes which can be triggered programmatically. ESP8266WiFi library offers specific functions to call sleep modes which can take settings parameters that change the callback jobs after wake-up like waking up with RF module powered off or on. The most important mode is DEEP_SLEEP because of the very low power consumption rates during sleep. Deep sleep mode is very common in projects that do data-logging at specific intervals and idle between measurements. In order to take advantage of this mode when using esp8266 arduino compatible module, ESP-01 standard, you need to make a little workaround and connect REST pin with the GPIO16 pin (which is not available in default 6 six pins).
Here is an example how to do it
ESP8266 Wifi module GPIO16 deep sleep
ESP8266 Wifi module GPIO16 deep sleep
After doing this connection you can use the following command to trigger the deep sleep mode:

Another thing that you need to know about the esp8266 arduino 01 version is that usually comes with two LEDs, a red one for power, and a blue one for data transmitting. The red LED is always on when the module is powered on and the blue led blinks during serial activities. For newer versions the producers eliminated the RED pin because of the continuous power consumption, so if you are going to buy one, try to find a version which has only the serial blue LED especially if you are going to use a battery power supply in your project. The differences can be seen in the following pictures:

ESP8266 Wifi module power led indicator

While in the left picture you can see two smd LEDs near the antenna, one for power indicator and one for data indicator, the right module has a single LED just to indicate the data transmission. PCB design can differ from one to another because producers tend to reduce the costs by cutting down the materials.

Talking with ESP-01 (AT / LUA / Arduino)

ESP8266-01 gives you many methods to communicate with it trough the RX/TX pins or over the air (OTA). The differences are not only in hardware but can be also in what kind of firmware is flashed out of the box. No matter what firmware comes default installed, you should be able to flash your preferred firmware by following the firmware flashing instruction from the datasheet. This module can be programmed using LUA code, Arduino code or directly trough AT commands and this gives us more freedom when embedding this device in our projects. Also there are few python firmware modes but i haven’t had the chance to test them. I personally choose to work with Arduino because of the past experience and tones of libraries available.

As it comes, out of the box, this module is ready to talk via AT commands without any other extra settings or configurations. There are many software applications which you can use to communicate via AT and have tones of ready made tools and functions which will make everything easier. I used ESPlorer and i totally recommend it, you can find it here. After booting, to be able to use AT commands, module should display “ready” on the serial monitor.

Few basic AT commands examples:

  • AT – response OK
  • AT+CWLAP – list nearby available WiFi networks
  • AT+GMR – check the firmware version
  • AT+CWJAP=”<access_point_name>”,”<password>” – join WiFi network using credentials
  • AT+CIFSR – get current allocated IP address

See here a complete list with AT instruction set.

In order to be able to talk with the ESP8266 arduino compatible module, you need to choose a way to connect it with your computer. You can communicate with the module via standard Serial communication RS232 by using an Arduino board as a proxy/bridge , by default Arduino having a USB to Serial converter integrated. If you are a beginner in development boards I totally recommend you one of the best Arduino books by Jeremy Blum, the best combination of a formaly trained electronics engineer and a Maker/Hacker. Arduino Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial converter. In order to use Arduino as a bridge, first you need to load an empty program on it. After doing that, you need to make the following connections in order to work:

ESP8266 Arduino UNO wire connections

UNOESP-01
RX RX
TX TX
3.3v VCC
GND GND
RST 3.3v / float
CH_PD 3.3v

After that you should be able to see data and send AT commands in Serial Monitor by selecting Arduino’s COM port, setting a proper baudrate, default should be 115200, and make the additional settings to read “Both NL & CR“.

Firmware Over The Air (FOTA) solution in every embedded DIY or commercial project is a highly desirable if not a required feature today, when every project core needs to scalable. So the possibility to upload your code from a remote computer via Wi-Fi connection rather then Serial is a high advantage in every project. First you need FOTA needs needs prerequisites. First firmware upload needs to be done via Serial, and if the OTA routines are correctly implemented in the program next uploads can be done over the air. Because the module needs to be exposed wirelessly, the chance to being hacked and loaded with maleficent code exists. You can improve your security by setting custom port and password. Check functionalities from the ArduinoOTA library that may help you to boost security. Because of the complexity of this procedures we will cover the full story in a future article, but for now be aware that this option exists and it works pretty good.

Another way to connect the esp8266 arduino module to computer is to use a TTL or FTDI USB-to-serial dedicated module. There are plenty of them on the market and there are quite cheap, but make no mistake, here quality does matter. You may encounter problems when working with it if ending up with a cheap one because of the differences in connections and also driver compatibility. Most used TTL / FTDI converters chips are CH340G, CP2102 and FT232RL. I personally used the first two ones and i have no problem when loading programs. Following connections need to be done:

ESP-01TTL / FTDI
RX TX
TX RX
VCC 3.3v
GND GND
RST 3.3v / float
CH_PD 3.3v

I highly recommend you not to use the TTL 3.3v power supply because most of them are not able to provide enough power to handle the esp8266 arduino compatible device. The embedded voltage regulator used on this modules are not the happiest choice and you may get in trouble if it cannot support ESP peeks. If you choose to use an external power supply don’t forget to setup a common ground in order to have a working circuit. You can find TTL modules that have TX rated at 3.3v, if not, you shod step-down the TX channel to protect your ESP-01 module. You can see bellow a wiring scheme between ESP-01 and CP2102 which includes a reset button connected to ground, and also GPIO0 for boot switch.

ESP8266-01 UART TTL connection GeeksTips.com

Here is a simple 3.3v divisor sketch using resistors:

3.3v divisor for ESP8266 Arduino

The most comfortable way to communicate with the ESP-01 is by using a dedicated ESP01 programmer module, which can be bought also from the same producers and the costs are very low. This kind of devices can have buttons integrated for RESET and BOOT switching and also come with a dedicated slot. All you need to do is to plug your esp and your done.

You can also build your own programmer if you have a bit of skills, you don’t need to be an expert. Here are few homemade tryouts:

In order to setup your Arduino IDE to work with your esp8266 arduino compatible module you need to make the following steps:

  1. Connect your ESP8266-01 Module to PC
  2. Open your Arduino IDE
  3. Go to File -> Preferences
  4. Add this link to Additional Board Manager
  5. Go to Tools -> Board Manager
  6. Find ESP8266 board set and activate it
  7. Select Generic ESP8266 board from Tools->Boards
  8. Choose your programmer COM port
  9. You are ready to go!

Arduino IDE ESP8266 board installation

Now, to be able to download the program to your ESP-01 module, you first need to put your device in the proper BOOT mode (Download code from UART). ESP8266-01 have the following boot modes:

MTDO / GPIO15GPIO0GPIO2ModeDescription
L L H UART Download code from UART
L H H Flash Boot from SPI Flash
H X X SDIO Boot from SD-card

Note that L = LOW (putting to Ground / -3.3v) and H = HIGH (putting to 3.3v)

After resetting the module in Download code from UART you should see a message containing “boot mode:[1,6]” in the serial monitor, if you are on the correct baudrate. A wrong baudrate setting will display garbage text / characters or nothing at all. After that you should be able to upload your sketch to ESP8266. When upload is done, module should reset itself. Don’t forget to pull HIGH the GPI0 or the module will get in Download mode again and you will not be able to see it working. The module can be rebooted at anytime by pulling REST pin to LOW. After each reset it will follow the boot sequence and program loading.

Once the ESP8266 board is installed and activated in Arduino IDE, you will be able to include all ESP WiFi libraries and examples that comes with the package. The most used library is ESP8266WiFi which offers many implementation examples like WiFiClient, WiFiServer, WiFiAccessPoint etc. You can find allot of projects examples over the internet, I for example, found great ideas on arduino.cc projecthub. Here is a simple Arduino blink example which you can use to test the esp module with the built in LED:

Off course, after that you can try a more complex example by loading a ESP8266 Arduino WiFi Client example program that sends data via WiFi to the data.spakfun.com iot platform:

Or if you need to make a server in your network, you can try ESP8266 Arduino Wifi Server example program:

And in the last example an ESP8266 Arduino WiFi Access Point which hosts a web server is created:

Final thoughts

After playing with this module for few weeks, i find it being one of the coolest gadget i ever used in my projects and i have nothing than beautiful words about it. If you are even just a bit attracted about development boards and you haven’t had the chance to play with ESP8266 series, this is one of the first thing that i recommend to get and play with. It easily checks every goal, the price is excellent, it has MCU integrated, it has Wi-Fi integrated, the signal range is pretty awesome, the size is excellent for embedding in most projects, and it can be powered by any average + batteries no problem.

In the further articles i will show you how i made to create a network of 5 ESP8266-01 in my house, and make them communicate each other to centralize data into a IoT web server. Also i want to come back with feedback about day to day behavior and especially power consumption.

Update: Multiple ESP8266 talking each other article ready. Find here an incredible story about a farmer from Europe who managed to implement a huge ESP8266 WiFi topology using more than 40 ESP modules in a real life example.

ESP8266 talk with each other -two esp connected

Hoping that this article inspired you, i kindly invite you share this articlesubscribe my YouTube channel and join the communities on social networks. Please feel free to comment or send suggestions / remarks so i can improve the content quality!

Save

Save

Save

Save

Save

Save

14 comments » Write a comment

  1. Good and thorough review. I’m looking forward to the multiple esp8266 communications tutorial.

    • Hello, I already implemented multiple ESP communication system in my house and I will write an tutorial about how to do that soon. Thank you for your interest!

  2. Pingback: Arduino temperature sensor – DHT22 Temperature and humidity vs. DS18B20 Temperature 1-Wire – Which to choose? – geekstips.com

  3. I see your website needs some fresh & unique articles.
    Writing manually is time consuming, but there
    is tool for this task. Just search for; Digitalpoilo’s tools

  4. Pingback: Communication between ESP8266 modules - Make them talk with each other

  5. Pingback: How to send push notifications to Android or IOS with ESP8266 - Arduino tutorial

  6. Pingback: How to monitor TV screen time for kids with Internet of Things | ESP8266

  7. Pingback: Smart House - Intelligent Home with Internet of Things - Introduction

  8. Pingback: Arduino Time Sync from NTP Server using ESP8266 WiFi module

Leave a Reply

Required fields are marked *.