Engineers Garage

  • Electronics Projects and 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 IoT-based analog clock using ESP32

By Nikhil Agnihotri May 7, 2024

In this project, we’ll design an analog display clock using ESP32. The clock is an Internet-of-Things (IoT) device that retrieves the local time from a Network Time Protocol (NPT) server and displays the time (as well as the date) like an analog clock.  

The display used to build this IoT clock is SSD1306. However, any display module can be used, and the code can be altered to fit within the clock’s dimensions. 

Without letting any more time run out, let’s build an analog clock. 

Components required 

  1. ESP32 x1
  2. SSD1306 OLED x1
  3. Connecting/Dupont wires

Circuit connections
To design the analog clock, we first must interface SSD1306 OLED with ESP32. The SSD1306 used in this project has a Serial Peripheral Interface (SPI) interface with the following pin diagram. 

To interface the SSD1306 OLED with ESP32, follow the circuit connections as described in the below table.

The circuit diagram of the IoT-based analog clock is represented in the below image.

Arduino sketch
After making circuit connections, upload the following sketch to ESP32. Remember to replace the SSID and Wi-Fi password in the sketch with your own. Also, you might need to adjust the time to the one in your time zone.

How it works
The clock is an IoT device. As such, the microcontroller (ESP32) connects with the Internet for the current local time for the given time zone from the NTP server. POSIX is the time received, provided as seconds passed since January 1st, 1970. 

The time is stored in a structure using Arduino’s time library. An analog clock is printed on the screen of the SSD1306 OLED. The hour, minute, and second hands are printed according to the current value of the time sent by the NTP server. The date and day of the week are also printed on the screen. The time is updated every second, and the screen is refreshed at the same interval.

The code
The sketch begins by importing the SPI.h, Wire.h, Adafruit_GFX.h, Adafruit_SSD1306.h, WiFi.h, and time.h libraries. 

  • The SPI.h, Wire.h, Adafruit_GFX.h and Adafruit_SSD1306.h libraries are required to work with the SSD1306 OLED. 
  • The WiFi.h library handles and connects with the Wi-Fi network to access the Internet. 
  • The time.h library converts the current POSIX time into the hours, minutes, seconds, month, day, and weekday values. 

This is followed by the declaration of constants and ESP32’s pin assignments with SSD1306. An object of Adafruit_SSD1306 is instantiated. The variables are declared to store the Wi-Fi SSID, Wi-Fi password, and time zone. 

In the setup() function, the baud rate for serial debug messages is set to 115200 bps. The Wi-Fi connection is initialized, and the local IP address is printed to the serial console. The SSD1306 OLED display is also initialized. The connection with the NTP server is verified. 

In the loop() function, the current time is retrieved from the NTP server and stored in a structure. The radius of the clock hands is set to 30 pixels. The numbers, indicating the hour ticks, are printed on the screen. 

Based on the current time’s hour, minute, and second values, the hour, minute, and second hands are printed at appropriate angles on the screen. The current date and day of the week are also printed on the screen. The screen is refreshed in each loop iteration. 

Results

https://www.engineersgarage.com/wp-content/uploads/2024/05/P60-DV.mp4

You may also like:


  • How to design an IoT-based digital watch using ESP32
  • MM5316 clock
    Home-made digital clock keeps time after 45 years

  • How to build an app-controlled alarm mat

  • How to make an Internet clock using ESP8266

  • What are the top weather APIs for the IoT?

Filed Under: Electronic Projects, ESP8266, Video
Tagged With: analog, analogclock, clock, ESP32, internetofthings, IoT, ntpserver, SSD1306
 

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

  • Is it possible to improve accuarcy of ad633
  • 12VAC to 12VDC 5A on 250ft 12AWG
  • Battery sensing circuitry for coin cell application
  • Copper Pour Support in Altium Softwarez
  • Input impedance matching network

RSS Electro-Tech-Online.com Discussions

  • Chinese Tarrifs – 104%!?!
  • An Update On Tarrifs
  • Tariff Updates from JLCPCB as of Today
  • Solar lighting motion detector
  • Telegram Based Alarm - Sensor cable protection

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Renesas launches 64-bit RZ/A3M with built-in 12 8MB memory
  • Hexagon’s Septentrio introduces 23 mm x 16 mm GNSS modules compatible with PX4 and ArduPilot
  • ITG Electronics releases gate drive transformers with 200 – 450 V DC capability
  • Stackpole introduces HCJ jumpers with 70.7 amp continuous current capability
  • Infineon releases MCU with 128K flash and multi-sense capabilities

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

  • Electronics Projects and 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