ESP8266 WiFi Internet real time clock

In the last ESP8266 project, I built a simple real time clock using a real time clock chip (DS3231 and DS1307), I used a 16×2 LCD to display time and date and 2 push buttons to set them.
Now, in this topic I’m going to make an internet clock based on the ESP8266 WiFi module (ESP-01), this clock gets time information from the internet and therefore there is no need for a real time clock chip such as DS3231, DS1307, DS1302 …
In this project time and date will be sent to Arduino IDE serial monitor and will be displayed on 16×2 LCD screen.

Before I start, if you want to see how to use the ESP-01 module for the first time, how to use it with Arduino IDE and how to program (upload sketches) it with Arduino, visit the following topic:
ESP8266 WiFi module programming with Arduino UNO board

And the page below shows how to interface the ESP-01 module with I2C LCD:
Interfacing ESP8266 ESP-01 module with I2C LCD

Also, the page below shows how to build a real time clock with ESP8266 module, DS3231 (or DS1307) and I2C LCD:
ESP8266 ESP-01 Real time clock with DS3231/DS1307

Components List:

  • ESP8266 ESP-01 module
  • 16×2 LCD screen
  • PCF8574 I/O expander (or PCF8574A)   —   PCF8574 datasheet
  • AMS1117 3V3 voltage regulator
  • 10uF capacitor
  • 0.1uF (100nF) ceramic capacitor
  • 5 x 10k ohm resistor
  • 330 ohm resistor
  • 10k ohm variable resistor or potentiometer
  • 5V source
  • Breadboard
  • Jumper wires

ESP8266 ESP-01 Internet WiFi clock

The Circuit:
Circuit schematic diagram is shown below.

ESP8266 ESP-01 Internet clock circuit with I2C LCD

(All grounded terminals are connected together)

The SDA and SCL lines of the I2C bus come from GPIO0 and GPIO2 of the ESP-01 (respectively), they are connected to PCF8574 SDA pin (#15) and SCL pin (#14).

The Code:
There are 3 libraries we’ve to add to Arduino IDE before we compile the code, the first one is for the I2C LCD which can be downloaded from the links below:
LiquidCrystal_I2C Library   —   direct link

The 2nd library is NTPClient, this library connects the ESP8266 WiFi to a time server, this server sends time information to the module. NTP: Network Time Protocol.
NTPClient Library   —   direct link

The last one is Arduino Time library, this library converts Unix timestamp (Unix epoch) into: seconds, minutes, hours, day of the week, day, month and year. The Unix epoch is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT).
Basically the time server sends time in Unix epoch format which needs to be converted, this library does all the job. Download links are below:
Arduino Time Library   —   direct link

The NTPClient library is configured to get time information (Unix epoch) from the server (GMT time) and an offset of 1 hour ( ==> GMT + 1 time zone) which is equal to 3600 seconds, configuration line is below:
NTPClient timeClient(ntpUDP, “”, 3600, 60000);

The full code is below:

Small Video:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.