Skip to content

ESP-01 with RTC and LCD Display

  • by

The ESP-01 module is a popular ESP8266 development board. Its popularity stems from its low cost and its small form factor. But one disadvantage of this board is the limited number of GPIO pins. Nevertheless, even with this very limited set of GPIOs, the ESP-01 can be connected with a Real Time Clock (RTC) module and a Liquid Crystal Display (LCD) using only two GPIO pins. That leaves the other two (2) GPIO pins available for other uses.

picture of the project ESP-01 with RTC and LCD display showing status OK on the fourth line of the LCD display
ESP-01 with RTC and LCD Display – OK
picture of the project ESP-01 with RTC and LCD display showing status NOK on the fourth line of the LCD display
ESP-01 with RTC and LCD Display – NOK

The digital clock shown above is made up of an ESP-01 ESP8266 module with the RTC module and the LCD display tied to GPIO-0 and GPIO-2 of the ESP-01. Not shown in the picture is the USB to TTL converter which is plugged on the PC and is also connected to the breadboard.

The digital clock displays the current time on the first row or the first line of the LCD display. The second line shows the current date. The third line contains the current temperature in Celsius and in Fahrenheit. The last line is the status line which displays the date and time of the last successful NTP synchronization of the clock. The status line also prints “OK” after a successful sync and changes to “NOK” when the clock needs an NTP sync or while awaiting for the next NTP clock sync to arrive.

On the software side, the clock is driven by the Time Library. With this library, synchronization by an RTC clock is as simple as providing a function which the library can call at a predetermined time interval.

As an added feature, the RTC clock is synchronized by an NTP server. Since the ESP-01 module is WiFi capable, it is easy to connect to the Internet and request a Time server with the current timestamp.


  • ESP-01 ESP8266 module
  • LCD with I2C Interface
  • Real Time Clock (RTC) module with I2C interface (DS3231 or DS3232)
  • USB to TTL converter
  • 3 pieces 10K ohm 1/4W resistors
  • 2 pieces pushbutton switches
  • one optional 0.1 microfarad ceramic capacitor
  • one optional 220 microfarad electrolytic capacitor
  • breadboard and wires

Notes on Real Time Clock Modules

DS1302 and DS1307 RTC modules are both low precision clock modules. The reason is the frequency drift of the temperature-sensitive crystals used on these modules. Therefore, the recommended clock module is DS3231 which is more precise because the crystal is inside the DS3231 chip. This results in a better temperature tracking and frequency adjustment.

Also, DS3231 clock modules are sold at the same price as the DS1302 and DS1307 RTC modules.

image of ESP-01 module for connection with an RTC and LCD display
ESP-01 ESP8266 Module
picture of DS3231 real time clock or rtc module for connection with esp-01 and lcd display
DS3231 RTC Module
image of 20x4 LCD display with I2C controller for esp-01 with RTC and LCD display project
20×4 LCD Module with I2C Controller Module
backside of the 20x4 LCD display showing the soldered in place I2C controller
Backside of the LCD Module Showing the Soldered I2C Module
the USB to TTL converter used for programming the ESP-01 with RTC and LCD display
CP2102 USB to TTL Converter

The ESP-01 Flasher/Programmer

schematic diagram of the ESP-01 flasher/programmer showing the SDA and SCL terminal for connecting the RTC clock module and the lcd display module
The ESP-01 Flasher/Programmer Using a USB to TTL Converter

The ESP-01 ESP8266 module does not have a built-in flasher or flash memory programmer. So, it needs a programmer adapter. But when breadboarding, a better alternative than a programmer adapter is to connect the module with a USB to TTL converter. An example of such a circuit is shown in the schematic diagram above.

The USB to TTL converter’s Transmit (TXD) and Receive (RXD) terminals are connected to the ESP-01 module in a reverse manner. This means that the TXD terminal of the USB converter is connected to the RXD terminal of the ESP-01 module. In the same manner, the RXD terminal of the USB converter is connected to the ESP-01 module’s TXD terminal. The USB connector end of the USB to TTL converter goes to the USB port of a PC or a laptop.

Take note that the ESP-01 is being powered by the 3.3V output from the USB to TTL converter. For added power supply stability, an optional 220 microfarad electrolytic capacitor is connected on the power supply rails. Also, a 0.1 microfarad ceramic capacitor may be connected to reduce high-frequency interference from the power supply line. If possible, you should place the ceramic capacitor near the ESP-01 power terminals.

The three (3) 10K resistors are used as pull-up resistors. These pull-up resistors ensure that the ESP8266 pins are at their expected states. For example, during reset, ESP8266 expects the GPIO-2 to be at a HIGH state.

Pressing the Reset pushbutton switch will restart the ESP-01 module and will boot and run the program loaded or installed in the flash memory. In order to put the ESP-01 module into flash programming mode, press and hold the Program switch, press and release the Reset switch, and finally release the Program switch.

The SDA terminal which is connected to GPIO-0 and the SCL terminal that is connected to GPIO-2 is where the LCD module and the RTC module’s corresponding SDA and SCL terminals will connect.

LCD Module Connection

picture of the LCD I2C controller with pinout guide for connection to the ESP-01 flasher programmer
LCD I2C Controller Showing Pin Connections

The LCD module’s I2C controller is connected to the Flasher/Programmer’s circuit thru the SDA and SCL terminals. The LCD module needs a 5 Volts supply so it must be connected to the USB to TTL converter’s 5V output.

RTC Module Connection

image of the DS3231 RTC clock module depicting terminal connections for the flasher programmer
DS3231 RTC Module With Terminal Connections

Connect the Real Time Clock (RTC) module to the same SDA and SCL terminals of the Flasher/Programmer. Basically, the LCD controller and the RTC module share the same I2C bus. Put in another way, their SDA and SCL pins are wired in parallel. Remember that the DS3231 RTC may be operated with 5 Volts or 3.3 Volts power supply. In this case, it is better to connect it to the 3.3 Volts output of the USB to TTL converter since the ESP-01 is also using the 3.3 Volts supply.

Programming the ESP-01 with RTC and LCD Display

We will be using the Arduino IDE to program the ESP-01, so you must already have it installed on your computer. If you need help in installing the Arduino IDE in Windows 10, please see: How to Install Arduino IDE on Windows 10.

Also, you need to install the ESP8266 Arduino Core in order to program ESP8266 based development boards on the Arduino IDE. Please take a look at the article How to Set Up Arduino IDE for ESP8266 Programming.

If your ESP-01 module is new or fresh from the factory, and you have not loaded any Arduino sketch on it, it still contains the factory-supplied AT Command Firmware. Loading an Arduino sketch or programming it with the Arduino IDE WILL ERASE the existing AT Command firmware.

You may want to backup the original firmware prior to programming your ESP-01 module. The backup firmware will come in handy in troubleshooting your ESP-01 module when it starts acting up. Learn how to save and restore ESP8266 firmware.

Sample Arduino IDE Sketch: ESP-01 with RTC and LCD Display

The sample Arduino sketch is a digital clock with two sync sources, the RTC clock and the Network Time Protocol (NTP). The digital clock uses the system clock which is synchronized by the RTC clock . The RTC clock is in turn synchronized by the NTP time.

Include Libraries

The ESP8266Wifi library and the WiFiUdp library are built-in libraries of ESP8266 Arduino Core. If you selected the proper board, “Generic ESP8266 Module” under the menu Tools -> Board, you don’t need to download these two libraries.

Time library by Michael Margolis Version 1.6.0. This library is maintained on Github by Paul Stoffregen. You may download it directly from Github, but it is advisable to use the Tools -> LIbrary Manager to install it, so that it will go the proper directory automatically.

screenshot of the library manager with the Time library highlighted
Library Manager with Time Library

There are many libraries for the DS3231 RTC module but this specific library is what we need. This library has support for I2C communication over ordinary GPIO pins of ESP8266. Download this library using the Tools -> LIbrary Manager.

another screenshot image of the LIbrary Manager with the RTClib library highlighted in yellow
Library Manager with RTClib Library

This is also a special library that supports I2C communications on GPIO-0 and GPIO-2 pins of ESP8266. Download from the provided link and put the decompressed library folder under Documents > Arduino > libraries if you’re using Windows 10: agnunez/ESP8266-I2C-LCD1602.

The complete library include is:


In the above code fragment, you need to provide your router’s SSID and password so that the ESP-01 module can connect to the internet. Select the NTP server you want to use for synchronizing the RTC clock by defining ntpServerName. Next, provide the timezone constant applicable to your location.

The Network Time Protocol uses the UDP protocol, so a Udp object is created and a localport is assigned.


The NTP code below is lifted from the Time Library example.

The function sendNTPpacket() is responsible for the assembly and sending of the NTP time request packet via UDP protocol.

The main NTP code is the getNTPTime() function.

It calls the sendNTPpacket() function to send the NTP time request and waits for a maximum of 1500 milliseconds for a reply from the NTP server. If a reply from the NTP server is received within 1.5 seconds, it decodes the NTP reply packet and returns the adjusted timestamp to the program calling the getNtpTime() function.

However, if the function getNtpTime() did not get a reply from the NTP server after 1.5 seconds, the function would time out and it would return the value of zero (0) to the calling program. Remember to check the return value of getNtpTime(), making sure it’s not zero (0), before using it. Or else, you may end up resetting your clock to zero which is the start of the Unix Epoch (0:0:0, January 1, 1970).

The Setup Function

The Loop Function

The Complete Sketch: ESP-01 with RTC and LCD Display

Download Source Code: ESP-01 with RTC and LCD Display

Related Articles on ESP-01 with RTC and LCD Display


How to Program ESP-01 with Arduino IDE
NodeMCU ESP32S Pin Configuration
NodeMCU V3 ESP8266 Pinout and Configuration
How to Save and Restore ESP8266 and ESP32 Firmware
How to Test NodeMCU V3 Using Esptool
How to Connect a DS3231 to NodeMCU V3


How to Install Arduino IDE on Windows 10
How to Set up Arduino IDE for ESP8266 Programming
How to Install Esptool on Windows 10

References on ESP-01 with RTC and LCD Display

ESP-01 on Wikipedia
DS3231 Datasheet
Liquid Crystal Display

Leave a Reply

Your email address will not be published. Required fields are marked *