Warning: Declaration of Db::query($query) should be compatible with mysqli::query($query, $resultmode = NULL) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 29

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Cannot modify header information - headers already sent by (output started at /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php:0) in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 168

Warning: session_start(): Cannot start session when headers already sent in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 169

Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64


Easy Basics: Project 021f ESP8266 ESP-01 WI FI module - deep sleep mode

of Acoptex.com in ESP8266 ESP-01

Basics: Project 021f

Project name: ESP8266 ESP-01 WI FI module - deep sleep mode

Tags: SP, ESP8266, WI FI module, ESP-01, V090, update firmware, Ai Thinker, AI-Cloud, SOC, GPIO, General Purpose Input Output, System On a Chip, IOT, internet of things, FTDI232, FTDI 232, USB to TTL, ESP8266 ESP-01 module, deep sleep mode

Attachments: sketch

In this project, you need these parts :

1. ESP8266 ESP-01 WI FI module 1pc

2.Arduino IDE ( you can download it from here  )

3.Jumper cables F-M, F-F, M-M

4. Resistor 1 pc (10 KOhm)

5. Momentary switch 1 pc

6. Breadboard 1 pc

7. USB to TTL serial converter 1 pc

8. USB mini cable 1 pc (optional)

9. Any voltage regulator LD1117V33, AMS1117 3.3 V or 78R33 (to get 3.3V) or  1 pc

or or 



We will learn what is deep sleep and how to use it with ESP8266 ESP-01 WI FI module. 

Understanding the deep sleep

If you made a project with an ESP8266 ESP-01 WiFi module which is powered from a battery, or if you just connected your ESP8266 ESP-01 WiFi module to a power bank, after running it for some time you realize the battery/power bank does not last long.

With most of the ESP8266 modules, you can not change the hardware to save power, but you can do it with software. If you use the sleep functions with the ESP8266, it will draw less power and your batteries will last longer. In this project we are going to speak about Deep Sleep with the ESP8266.

Types of Sleep

There are three types of sleep modes: modem sleep, light sleep, and deep sleep.

These modes have different purposes and they should be used in different applications.

Deep sleep

For this project we want that everything will be always off, except the Real Time Clock (RTC) to keep the time on ESP8266. If we use the deep sleep mode, the most efficient power saving option and the ESP8266 chip draws approximately 20uA only.

With deep sleep the 4 steps are in place:

  1. ESP8266 connects to Wi-Fi;
  2. The ESP8266 performs an action (reads a sensor, publishes an MQTT message and so on);
  3. Sleeps for a defined number of microseconds;
  4. Repeats that process over and over.

Other sleep modes

Other sleep modes like the modem sleep and light sleep are helpful if you still need to have your ESP8266 functioning and you want some additional power options. However, if you need some serious power saving, Deep Sleep is the only way to go.

Understanding the USB to TTL converter

You can read more about them here.

Understanding the ESP8266 WI FI module

The ESP8266 WiFi Module is a self contained SOC (System On a Chip) with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network.

The ESP8266 WiFi Module is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.

Each ESP8266 WiFi Module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino board and get about as much WiFi-ability as a WiFi Shield offers.

The ESP8266 WiFi Module is an extremely cost effective board. This module has a powerful enough on-board processing and storage capability that allows it to be integrated with the sensors and other application specific devices through its GPIOs (General Purpose Input Output) with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, including the front-end module, is designed to occupy minimal PCB area. The ESP8266 supports APSD for VoIP applications and Bluetooth co-existance interfaces, it contains a self-calibrated RF allowing it to work under all operating conditions, and requires no external RF parts.

In short, the ESP8266 module is a TTL "Serial to Wireless Internet" device, a small microprocessor with built in wi-fi. It is faster than most Arduino boards and has more memory than most Arduino boards and has less pins than an Arduino board.

The ESP8266 comes in a wide variety of versions (as shown in the figure below).

See the module list here.
ESP8266 AI THINKER IC (chip)


  • 802.11 b/g/n
  • Built-in Tensilica L106 ultra-low-power 32-bit micro MCU, clocked at 80 MHz and 160 MHz, supporting RTOS
  • Built-in 10bit high precision ADC
  • Built-in TCP/IP stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator, and power management components, +20dBm output power in 802.11b mode
  • A-MPDU, A-MSDU aggregation and 0.4s guard interval
  • WiFi @ 2.4GHz, supports WPA/WPA2 security mode
  • Support AT remote upgrade and cloud OTA upgrade
  • Support STA/AP/STA+AP working mode
  • Supports Smart Config features (including Android and iOS devices)
  • HSPI,UART, I2C, I2S,IR Remote Control,PWM,GPIO
  • Deep sleep current is 10uA and shutdown current is less than 5uA
  • Wake up, connect and transfer packets within 2ms
  • Standby power consumption less than 1.0mW (DTIM3)
  • Operating temperature range: -40°C - 125°C


  • create a web server
  • send HTTP requests
  • control outputs
  • read inputs and interrupts
  • send emails
  • post tweets


The ESP8266 WI FI module can be controlled from your local wifi network or from the internet (after port forwarding set on your router). The ESP8266 communicates with the Arduino through a serial interface.  It uses the Arduino’s Rx and Tx pins (digital pins 0 and 1) connected to the ESP8266 ESP-01 module for receiving commands and communicates back. The module features a full TCP/UDP stack support and can be configured as a web server. ESP-01 module powers the onboard ESP8266 through 3.3V. You will have to use a voltage regulator AMS1117 3.3 V or like the 78R33 to step down the 5V from the Arduino to 3.3V or voltage divider (You can find some info here with online calculation sheet) in order to power up the ESP8266.

The ESP8266 does not come with an USB connector on it. You need an additional component for ESP8266 to communicate with the PC or laptop via USB port. It's called USB to TTL serial adapter (for example, USB adapter for ESP8266 ESP-01, FT232RL FTDI USB to TTL Serial Adapter, CP2102 USB to TTL UART converter). So we can either use a USB to TTL serial adapter (converter) or use an Arduino to communicate and upload the code to the ESP8266.

ESP-01 adapters

ESP8266 ESP-01 module

We will use ESP8266 ESP-01 module in this project. It has 2 GPIO pins that can be programmed to turn an LED or a relay ON/OFF through the internet. 

The ESP-01 module contains the ESP8266 MCU and a flash memory chip. There are two LED's: a red one which indicates power is connected to the module, and a blue one which indicates data flow, and can also be controlled by user programming. The Wi-Fi antenna is the PCB trace that covers the top of the module; it's called a Meandered Inverted-F Antenna (MIFA,) is surprisingly efficient, and only mildly directional.

There are eight connection pads near the bottom of the module. Usually, two 4-pin male headers are inserted in the rear of the module and soldered on the front. This makes the I/Os accessible, but is not breadboard friendly, and requires flywires from the ESP-01 to a solderless breadboard. This technique works, but it is messy. 

ESP8266 ESP-01 module has three operational modes: 

1. Access Point (AP) — In AP, the Wi-Fi module acts as a Wi-Fi network, or access point (hence the name). It allows other devices to connect to it. And establishes a two-way communication between the ESP8266 and the device that is connected to it via Wi-Fi. 

2. Station (STA) — In STA mode, the ESP-01 can connect to an AP (access point) such as the Wi-Fi network from your house. This allows any device connected to that network to communicate with the module. 

3. Both — In this mode ESP-01 act as both an AP as well as in STA mode. Refer to the following site for more ESP8266 AT commands. 

ESP8266 ESP-01 module can be set in Flash mode or UART download mode (for uploading new firmware or program) and Boot mode or Flash Boot Mode (normal startup and execution of existing firmware or program).

ESPlorer — Integrated Development Environment (IDE) for ESP8266 developers.
The essential multiplatforms tools for any ESP8266 developer from luatool author’s, including a LUA for NodeMCU and MicroPython. Also, AT commands are supported.
Required JAVA (SE version 7 and above) installed.
You can download it here.
Supported platforms
  • Windows(x86, x86-64)
  • Linux(x86, x86-64, ARM soft & hard float)
  • Solaris(x86, x86-64)
  • Mac OS X(x86, x86-64, PPC, PPC64)
Detailed features list
  • Syntax highlighting LUA and Python code
  • Code editor color themes: default, dark, Eclipse, IDEA, Visual Studio
  • Undo/Redo editors features
  • Code Autocomplete (Ctrl+Space)
  • Smart send data to ESP8266 (without dumb send with fixed line delay), check correct answer from ESP8266 after every lines.
  • Code snippets
  • Detailed logging

Signals and connections of the ESP8266 ESP-01 WI FI module


TXD (TX, TXO or UTXD) - transmit pin. Connected to Arduino Uno pin 1.

RXD (RX, RXI or URXD) - receive pin. Connected to Arduino Uno pin 0.

VCC (3V3 or 3.3V) - power supply pin (3-3.6V). Connected to 3.3V DC 1A and more external power supply. The current required for the ESP-01 during Wi-Fi operation vary from 250mA to 750mA.

RST (RESET) - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.

CH_PD (CHIP_EN or EN) - Chip enable. Keep it on high (3.3V) for normal operation.

GND - Ground. Connected to Arduino board GND pin

GPIO0, GPIO2 (IO0, IO2) - General Purpose Input Output pins. GPIO0 also controls the module mode (programming or normal operation). In our case (normal operation), it shall be connected to 3.3V (high). GPIO2 is not used in this example.


1. Programming (uploading sketch) using ESP01 programmer UART

It is very easy. Simply insert ESP8266 ESP-01 module to ESP01 programmer UART. However to go to flash mode you need to have GPIO0 pin grounded (attached to GND pin). A small modification on the back of ESP01 programmer UART posible to make the life more easy. You can just shift jumper from GND-GND to GND-GPIO0 position.

2. Programming (uploading sketch) using USB to TTL converter with DTR Pin or without DTR Pin

3. Programming (uploading sketch) using Arduino Uno board

The ESP8266 powered up using a separate 3.3 V power source or a voltage regulator AMS1117 3.3 V or  78R33 or a voltage divider. Note: Do not plug in ESP8266 ESP-01 module directly to 3.3V Arduino Uno board pin as the ESP8266 ESP-01 module may draw more current than the 3.3V regulator on your Arduino can supply so you can damage your Arduino board.

4. Final wiring after sketch uploaded to ESP8266 ESP-01 module

You need to solder a wire as shown below, because pin GPIO16 needs to be connected to the RST pin. 

Step by Step instruction

1. Adding ESP8266 platform to Arduino IDE 

the Arduino environment has to be set up to make it compatible with the 
ESP-01 module. It is required to have Arduino version 1.6.4 or higher in order to install the ESP8266’s platform packages.

The Arduino environment has to be set up to make it compatible with the ESP8266 ESP-01 module. It is required to have Arduino IDE version 1.6.4 or higherin order to install the ESP8266’s platform packages.

  1. Open Arduino IDE. 
  2. Open the Preferences window from the Arduino IDE. Go to File -> Preferences.
  3. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field and click the “OK” button. If you already have a URL in there, and want to keep it, you can separate multiple URLs by placing a comma between them. (Arduino 1.6.5 added an expanded text box, separate links in here by line.)

  4. Open Boards manager. Go to Tools -> Board -> Boards Manager…

  5. There should be a couple new entries in addition to the standard Arduino boards. Look for esp8266. or scroll down to the ESP8266 entry (usually at the bottom). Select the ESP8266 entry. When you click it an install option will appear. Select the latest version and click install
  6. The board definitions and tools for the ESP8266 include a whole new set of gcc, g++, and other reasonably large, compiled binaries, so it may take a few minutes to download and install (the archived file is ~110MB). Once the installation has completed, an Arduino-blue “INSTALLED” will appear next to the entry.
  7. Choose your ESP8266 board. Go to Tools -> Board -> Generic ESP8266 Module
  8. You will see Generic ESP8266 Module on the bottom of the Serial Monitor window.

2. Uploading sketch to ESP8266 ESP-01 module using USB to TTL converter with DTR Pin or without DTR Pin or Using ESP01 programmer UART

  1. Do wiring.
  2. Open Arduino IDE.
  3. Plug your USB to TTL converter with DTR Pin or without DTR Pin or ESP01 programmer UAR into your PC USB port.
  4. Choose your ESP8266 board. Go to Tools -> Board -> Generic ESP8266 Module
  5. Select the correct com port.
  6. Verify and upload the sketch to your ESP8266 ESP-01 module. AT commands will not work after that. You need to Flash the firmware to enable them again.
  7. Open Serial monitor at baud rate of 9600 bps.
  8. As you can see we put a 0 inside the deepSleep function, so your ESP8266 only awakes when something resets the board, it can be the press of a pushbutton or a magnetic reed switch being closed for example.When the reset button is pushed, wakes the ESP8266 up, does the programmed task and goes back to sleep until a new reset event is triggered.


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019