Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • 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
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • 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

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

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 EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • 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 © 2025 WTWH Media 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 WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • 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
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe