Beginner to Intermediate

Build a Digital Clock

A digital clock is one of the most popular microcontroller projects for beginners. It accurately displays the current time using an LCD, OLED, 7-segment LED or TFT display and can include alarms, calendars, temperature monitoring and automatic time synchronisation. This project demonstrates how to build a reliable digital clock using an Arduino, ESP32 or STM32 together with a Real-Time Clock (RTC) module.

Digital Clock

Project Overview

The clock uses a Real-Time Clock (RTC) module to maintain accurate time, even when the main power is disconnected.

The microcontroller periodically reads the RTC and updates the display every second.

Optional features include alarms, date display, automatic daylight-saving adjustment, Wi-Fi time synchronisation and indoor temperature monitoring.

Project Difficulty

ItemValue
Difficulty⭐⭐ Beginner–Intermediate
Build Time2–5 Hours
Supply Voltage5 V DC (3.3 V for some controllers)
Time AccuracyDepends on RTC module
DisplayLCD, OLED, TFT or 7-Segment LED

Main Sections

Section Function
Microcontroller Controls the clock and updates the display.
RTC Module Keeps accurate time.
Display Shows time and date.
Backup Battery Maintains time during power failure.
Buttons Set time, date and alarms.
Buzzer Provides alarm output.

Popular RTC Modules

Module Features
DS1307 Low-cost RTC with battery backup.
DS3231 High-accuracy RTC with temperature-compensated crystal.
PCF8563 Low-power RTC for battery-operated devices.
RV-3028 Ultra-low-power precision RTC.

Typical Components

QuantityComponent
1Arduino Nano, ESP32 or STM32
1DS3231 RTC Module
116×2 LCD, OLED, TFT or 7-Segment Display
1CR2032 Backup Battery
2–4Push Buttons
1Piezo Buzzer (Optional)
15 V Power Supply
SeveralConnecting Wires and PCB

How the Circuit Works

The RTC module continuously keeps track of the current time using its own crystal oscillator.

The backup battery allows the RTC to continue running even when the main power supply is disconnected.

The microcontroller communicates with the RTC through the I²C interface, retrieves the current time and updates the display once every second.

When alarm functions are enabled, the microcontroller compares the current time with the programmed alarm time and activates the buzzer when they match.

Applications

  • Desk clocks.
  • Wall clocks.
  • Laboratory timers.
  • Digital alarm clocks.
  • School clocks.
  • Industrial control systems.
  • Attendance systems.
  • Home automation.

Testing

  1. Verify the supply voltage.
  2. Check I²C communication with the RTC.
  3. Set the correct time and date.
  4. Confirm the display updates every second.
  5. Disconnect power briefly and verify the RTC retains the correct time.
  6. Test the alarm function.
  7. Verify all buttons operate correctly.

Troubleshooting

Problem Possible Cause
No display No power supply or incorrect display wiring.
Wrong time RTC not set or backup battery discharged.
Clock loses time Faulty RTC module or missing backup battery.
Buttons not responding Incorrect wiring or software configuration.
Alarm not working Incorrect alarm settings.

Project Improvements

  • Add automatic Internet time synchronisation using Wi-Fi.
  • Display indoor temperature and humidity.
  • Add a colour TFT display.
  • Include multiple alarms.
  • Automatically adjust display brightness.
  • Add Bluetooth smartphone configuration.
  • Include a stopwatch and countdown timer.
  • Display weather information using an ESP32.

Skills Learned

  • Real-Time Clock (RTC) operation.
  • I²C communication.
  • Microcontroller programming.
  • Display interfacing.
  • Alarm programming.
  • Timekeeping systems.

Safety Notes

  • Observe the correct supply voltage for the microcontroller and display.
  • Install the backup battery with the correct polarity.
  • Avoid short-circuiting the battery terminals.
  • Protect the clock from moisture and excessive heat.
  • Back up the firmware before making software modifications.

Key Points

  • An RTC module provides accurate timekeeping even during power failures.
  • The DS3231 is one of the most accurate and widely used RTC modules.
  • I²C communication simplifies interfacing between the microcontroller and the RTC.
  • Additional features such as alarms, temperature display and Wi-Fi synchronisation can easily be added.
  • A digital clock is an excellent beginner project for learning embedded electronics and programming.

Next Project

Continue by building a Digital Calendar and Weather Station, combining a real-time clock, temperature and humidity sensors, and Wi-Fi connectivity to display time, date and environmental conditions on a single screen.

Next Project → Digital Weather Station