Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe

How to make an Internet clock using ESP8266

By Nikhil Agnihotri December 3, 2023

The Internet of things (IoT) offers several interesting applications, including an Internet clock. This timekeeping device uses an Internet connection to synchronize the time with a time server. This ensures highly accurate timekeeping, aligning with online servers’ coordinated universal time (UTC). 

Most Internet clocks use NTP, a protocol designed to synchronize clocks over a network. Internet clocks maintain high accuracy by syncing with atomic clocks or GPS time. These clocks also automatically adjust to the correct time zone based on the network location. 

In this project, we’ll design an Internet clock using ESP8266. The time and weather information is attained by the clock from WeatherAPI.com and is displayed on an SSD1306 OLED screen. Any display screen, such as one that’s larger in size, can be used to display the clock. 

Components 

1. ESP8266/ESP32 x1
2. SSD1306 OLED x1
3. Connecting or Dupont wires
4. MicroUSB cable to connect ESP with computer
5. Power supply for ESP8266/ESP32

Circuit connections
For this project, you’ll need to interface ESP8266 or ESP32 with an SSD1306 OLED. We’re building our project using ESP8266. The SSD1306 OLED display is a 7-pin OLED module with SPI and I2C interfaces. A 0.96″ OLED is in the below image. 

To interface SSD1306 OLED with ESP8266, make the circuit connections as described in the below table.

Remember to replace the SSID and network key in the sketch with those of your personal WiFi connection. Also, replace the API key with yours from WeatherAPI.com (which can be received by registering there).

How this project works
A microcontroller with Ethernet or WiFi capabilities (built-in or through an external shield or a breakout board) is necessary to build this Internet clock. 

We use ESP8266 to build our clock, which has WiFi functionality, so it easily connects with any network. When ESP8266 is powered on, it connects with WiFi using the provided SSID and network password. Then, it makes an HTTP request to WeatherAPI.com for the JSON data from the Realtime API. 

The JSON data that’s received is de-serialized, and the specific data about date, time, location, and weather are retrieved. This data is formatted and displayed on the OLED display in a user-defined template. 

The code
The sketch begins by importing ESP8266WiFi.h, ESP8266HTTPClient.h, ArduinoJson.h, SPI.h, Wire.h, Adafruit_GFX.h, and the Adafruit_SSD1306.h libraries. 

Here’s a summary of each process:

  • ESP8266WiFi.h is used to connect ESP8266 to the WiFi network. 
  • ESP8266HTTPClient.h makes HTTP requests from ESP8266 to the web server, which is WeatherAPI.com. 
  • ArduinoJson.h parses and de-serializes the JSON data received from WeatherAPI’s Realtime API. 
  • SPI.h and Wire.h are used to interface SSD1306 OLED with ESP8266. 
  • Adafruit_GFX.h and Adafruit_SSD1306.h libraries manage the SSD1306 OLED display. 

Next, the variables are declared for the pin assignments that interface ESP8266 with SSD1306 OLED. An object “display” of the Adafruit_SSD1306 class is instantiated. The variables are declared to store the SSID, the WiFi network password, and the API key from WeatherAPI.com. Then, some global variables are declared to store the temperature, humidity, wind speed, precipitation, date, time, formatted date, formatted time, and the day of the week. 

The user-defined function dayOfWeek() is defined next to derive the day of the week from the Gregorian calendar date using Zeller’s Congruence algorithm. The user-defined function fetchData() is also defined so the HTTP request to WeatherAPI’s Realtime API is made, and the data is received as a JSON document. 

The user-defined function parseData() de-serializes the JSON data, extracting the date, time, location, temperature, humidity, wind speed, precipitation, and weather conditions into respective variables. The date, time, location, and weather information are converted to the proper formats for display. 

The user-defined function displayClock() places the date, time, location, and weather information on the SSD1306 OLED in a pre-defined layout. It’s important to note that the program in fetchData() is coded so that ESP8266 retrieves the data from the Realtime API via an IP lookup. The clock automatically detects the current location, and retrieves the real-time date, time, location, and weather information based on the location. 

In the setup() function, the ESP8266 board is connected to the WiFi network, and the SSD1306 OLED display is initialized. In the loop() function, the fetchData() is called to retrieve the date, time, location, and weather information based on the IP lookup. This is then displayed on the OLED screen by calling the displayClock() function.

A five-second delay is provided before the clock updates. It might take additional time for the clock to update the date, time, and other information depending upon your network connectivity and response time from the WeatherAPI server.   

Results

You may also like:


  • What are the top weather APIs for the IoT?

  • How to design an IoT-based smart alarm

  • How to manage data on ESP32 for IoT projects

  • How to send email alerts from Arduino/ESP8266/ESP32 through IFTTT

  • What to expect from microcontrollers in 2023

  • MicroPython: Time-related functions, timers & interrupts in ESP8266 and ESP32

Filed Under: Electronic Projects, ESP8266
Tagged With: internetclock, internetofthings, IoT, weatherapi, wifi
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • Convert Open Collector comparator to PushPull?
  • PNA causality improved significantly reason
  • How to generate ATF34143 transistor layout in ADS2025?
  • SX1262 From Component Selection Pitfalls to a Working LoRa Link
  • What do they connect Y capacitors to in ships?

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • What if battery is always connected to the charger?
  • Relay terminals
  • Semi-automatic battery handler
  • Coin Battery Case 261104
  • How Can You Identify the Main Causes of Noise in an Analogue Circuit?

Featured Tutorials

LoRa and LoRaWAN: A Complete Guide to Wireless Communication

  • Best practices for securing LoRa networks
    Best practices for securing LoRa networks
  • Understanding LoRa architecture: nodes, gateways, and servers
    Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
    Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
    How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
    How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices
    How communication works between two LoRa end-node devices
More Tutorials >

Recent Articles

  • Nuvoton and Qt Group add MCU HMI support
  • MicroStrain by HBK adds compact inertial sensors
  • Allegro MicroSystems expands 48V adas portfolio
  • SemiQ previews 1700 V SiC module
  • pSemi adds wideband RF switch

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe