Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Internet Clock with ESP32 & LCD Display using NTP Client
ESP32 Projects IoT Projects

Internet Clock with ESP32 & LCD Display using NTP Client

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20221 Comment4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
ESP32 Internet Clock
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this project, we will make an Internet Clock using ESP32 Board & 16X2 LCD Display using NTP Client, i.e. Network Time Protocol.


Overview

In this project we will design an Internet Clock using ESP32 Wifi Module. We will fetch the time and data from the internet using the ESP32 controller. The internet time clock has a precision of 0.02 to 0.10 seconds. In some of the previous projects, I used the RTC Module like DS1307, DS3231 or PCF8563 to get the time. But what if there is no availability of any RTC Module. The next disadvantage of RTC Module is the poor accuracy as it requires manual adjustments over and over again to keep time/date synchronized.

The solution here is to use the Network Time Protocol (NTP). If your ESP32 project has access to the Internet, you can get date and time (with precision within a few milliseconds of UTC) for FREE. You don’t need any additional hardware.

You can check one of my previous projects here: IoT Analog/Digital Clock as well as Arduino GPS Clock


Bill of Materials

Following are the components required for making this project. All the components can be purchased from Amazon. The components purchased link is given below.

S.N.ComponentsQuantityPurchase Links
1ESP32 Board1Amazon | AliExpress
216x2 LCD Display1Amazon | AliExpress
4Connecting Wires10Amazon | AliExpress
5Breadboard1Amazon | AliExpress



What is an NTP (Network Time Protocol)?

The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.

The protocol can be used to synchronize all networked devices to Coordinated Universal Time (UTC) within a few milliseconds, example 50 milliseconds over the public Internet.

How does NTP work?

The NTP client initiates a time-request exchange with the NTP server. As a result of this exchange, the client is able to calculate the link delay and its local offset and adjust its local clock to match the clock at the server’s computer.

Once synchronized, the client updates the clock about once every 10 minutes, usually requiring only a single message exchange. In addition to client-server synchronization. This transaction occurs via the User Datagram Protocol on port 123.


Internet Clock with ESP32 & LCD Display using NTP Client

Now let us interface 16×2 I2C LCD Display with ESP32 Board. Then we will connect the ESP32 to wifi network and fetch the time and date. Thus a simple internet clock using ESP32 can be made.

The connection between 16X2 I2C LCD and ESP32 is fairly simple. Connect the SDA & SCL pin of I2C LCD to GPIO21 & GPIO22 of ESP32 respectively. The LCD requires 5V VCC. So, connect its VCC pin to Vin pin of ESP32. Connect the GND to GND.

ESP32 16X2 LCD Connection


Libraries Requirement

To make an ESP32 Internet Clock with LCD Display, we need few libraries:

1
2
3
#include <NTPClient.h>         // Include NTPClient library      
#include <TimeLib.h>           // Include Arduino time library      
#include <LiquidCrystal_I2C.h> // Include LiquidCrystal_I2C library  

We will use NTPClient Library first. This library connects the ESP32 WiFi to a time server, the server sends time information to the module.

Then we have Time library which converts Unix timestamp (Unix epoch) into seconds, minutes, hours, day of the week, day, month and year.

The I2C LCD Library is used to interface 16×2 I2C LCD with ESP32 Board.



1. Download NTPClient Library
2. Download Time Library
3. Download I2C LCD Library


Source Code/Program for ESP32 Internet Clock

Here is a source code for getting NTP Time from Server. Before uploading the code to the ESP32 Board, you need to make changes in the line below to match your time Zone.

C++
1
NTPClient timeClient(ntpUDP, "asia.pool.ntp.org", 20700, 60000);

Currently, I am staying in Nepal. Nepal is 5 hours and 45 minutes ahead of Coordinated Universal Time (UTC Time). So I converted +5 hr 45 Mins to Seconds.

+5 hr 45 Mins = 5x60x60 + 45×60 = 20700

So change this Timing according to your time Zone and Country in order to get correct time.

Also in the below code, make changes to the Wifi SSID & Password.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>              
#include <TimeLib.h>                
#include <LiquidCrystal_I2C.h>      
LiquidCrystal_I2C lcd(0x27, 16, 2);
 
 
const char *ssid     = "Alexahome";
const char *password = "12345678";
 
WiFiUDP ntpUDP;
 
 
NTPClient timeClient(ntpUDP, "asia.pool.ntp.org", 20700, 60000);
 
char Time[ ] = "TIME:00:00:00";
char Date[ ] = "DATE:00/00/2000";
byte last_second, second_, minute_, hour_, day_, month_;
int year_;
 
 
void setup() {
 
  Serial.begin(115200);
  lcd.begin(21, 22);                 // Initialize I2C LCD module (SDA = GPIO21, SCL = GPIO22)
  lcd.backlight();                  
  lcd.setCursor(0, 0);
  lcd.print(Time);
  lcd.setCursor(0, 1);
  lcd.print(Date);
 
  WiFi.begin(ssid, password);
  Serial.print("Connecting.");
 
  while ( WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("connected");
  timeClient.begin();
}
 
void loop() {
 
  timeClient.update();
  unsigned long unix_epoch = timeClient.getEpochTime();    // Get Unix epoch time from the NTP server
 
  second_ = second(unix_epoch);
  if (last_second != second_) {
 
    minute_ = minute(unix_epoch);
    hour_   = hour(unix_epoch);
    day_    = day(unix_epoch);
    month_  = month(unix_epoch);
    year_   = year(unix_epoch);
 
 
    Time[12] = second_ % 10 + 48;
    Time[11] = second_ / 10 + 48;
    Time[9]  = minute_ % 10 + 48;
    Time[8]  = minute_ / 10 + 48;
    Time[6]  = hour_   % 10 + 48;
    Time[5]  = hour_   / 10 + 48;
 
 
    Date[5]  = day_   / 10 + 48;
    Date[6]  = day_   % 10 + 48;
    Date[8]  = month_  / 10 + 48;
    Date[9]  = month_  % 10 + 48;
    Date[13] = (year_   / 10) % 10 + 48;
    Date[14] = year_   % 10 % 10 + 48;
 
    Serial.println(Time);
    Serial.println(Date);
 
    lcd.setCursor(0, 0);
    lcd.print(Time);
    lcd.setCursor(0, 1);
    lcd.print(Date);
    last_second = second_;
 
  }
  delay(500);
}


Once the code is uploaded, the ESP32 will try connecting to the Network. After it connects to Network, the LCD will start displaying the correct time and date.

Here is an application of NTP Clock in one of the project: ESP32 Weather Forecasting. You can follow this post as well to learn more about the Internet Clock.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleBMP180 Pressure Temperature Monitor on Thingspeak with ESP8266
Next Article UV Index Meter with ESP32 & UV Sensor ML8511

Related Posts

IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

Updated:February 1, 20261K
View 1 Comment

1 Comment

  1. Sanjay Rastogi on July 9, 2022 2:51 PM

    Dear sir, Internet Clock with ESP32 & LCD Display using NTP Client but i want ESP8266 use what can I modified in circuit. Please sir haple.

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Pulse Rate (BPM) Monitor using Arduino & Pulse Sensor
    Pulse Rate (BPM) Monitor using Arduino & Pulse Sensor
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Earthquake Detector Alarm with Accelerometer & Arduino
    Earthquake Detector Alarm with Accelerometer & Arduino
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.