Arduino Project · Intermediate Series
Simple Digital Clock
with RTC & LCD
Build a real-time digital clock using Arduino UNO, a DS3231/DS1307 RTC module, and a 16×2 I2C LCD display. Time stays accurate even after power loss.
📺 Live Preview — What your LCD will display
Time: 00:00:00
Date: 07/04/2026
This mirrors exactly what scrolls on your 16×2 LCD screen in real time.
1Components Required
Arduino UNO
× 1
DS3231 or DS1307 RTC
× 1 (DS3231 preferred)
16×2 I2C LCD Display
× 1
I2C Module for LCD
× 1 (optional, recommended)
CR2032 Coin Cell
× 1 (backup battery)
Breadboard
× 1
Jumper Wires
Male-to-Male
USB Cable
For programming
2Working Principle
1. Time Keeping (RTC)
The DS3231 has an internal crystal oscillator that tracks hours, minutes, seconds, day, month, and year. A CR2032 coin cell keeps time even when Arduino is off.
2. I2C Communication
Arduino communicates with both the RTC module and LCD over the I2C bus using SDA (A4) and SCL (A5). Both devices share the same two wires.
3. Display Update
Every second, Arduino reads time data from the RTC, formats it, and pushes it to the 16×2 LCD — Row 1 shows HH:MM:SS, Row 2 shows DD/MM/YYYY.
3Circuit Diagram
💡 Both the RTC module and LCD share the same SDA/SCL lines — that's the power of the I2C bus.
4Wiring Connections
RTC Module (DS3231 / DS1307)
| RTC Pin | Connect To (Arduino) | Wire Color |
|---|---|---|
| VCC | 5V | 🔴 Red |
| GND | GND | ⚫ Black |
| SDA | A4 | 🟡 Yellow |
| SCL | A5 | 🟠 Orange |
16×2 I2C LCD Display
| LCD Pin | Connect To (Arduino) | Wire Color |
|---|---|---|
| VCC | 5V | 🔴 Red |
| GND | GND | ⚫ Black |
| SDA | A4 | 🟡 Yellow |
| SCL | A5 | 🟠 Orange |
ℹ️
Both the RTC and LCD use the same I2C bus (SDA and SCL lines). They have different I2C addresses so they don't conflict. The LCD I2C backpack's address is usually 0x27 or 0x3F — check with an I2C scanner sketch if unsure.
5Step-by-Step Instructions
1
Install required libraries
In Arduino IDE, go to Sketch → Include Library → Manage Libraries. Search and install: RTClib by Adafruit, LiquidCrystal I2C by Frank de Brabander, and ensure Wire.h is available (it's built-in).
💡 RTClib works with both DS3231 and DS1307. Just change the object type in code.
2
Insert CR2032 battery into RTC module
Before wiring, slide the CR2032 coin cell into the battery holder on the back of the RTC board. This ensures your time is retained even when Arduino is unplugged.
3
Set up breadboard power rails
Connect Arduino's 5V to the breadboard's red (+) rail and GND to the blue (−) rail. Both the RTC and LCD will draw power from here.
4
Wire the DS3231 RTC module
Connect RTC VCC → 5V rail, GND → GND rail, SDA → Arduino A4, SCL → Arduino A5.
5
Wire the 16×2 I2C LCD
Connect LCD VCC → 5V rail, GND → GND rail, SDA → Arduino A4, SCL → Arduino A5. Both devices share these same two data wires — that's I2C in action!
6
Find your LCD's I2C address
Upload the I2C Scanner sketch (available in Arduino examples) to find the LCD's address. It's usually
0x27 or 0x3F.💡 Update the address in the code:
LiquidCrystal_I2C lcd(0x27, 16, 2);7
Upload the code & set the time
The first upload automatically sets the RTC time to your computer's compile time. After uploading once, comment out the
rtc.adjust() line and upload again to prevent time reset on every restart.8
Test & verify the display
The LCD should show the current time on Row 1 (HH:MM:SS) and the date on Row 2 (DD/MM/YYYY), updating every second. Adjust the LCD contrast using the potentiometer on the I2C backpack if text is invisible.
6Arduino Code
simple_clock.ino
// Simple Digital Clock using Arduino UNO // Components: DS3231 RTC + 16x2 I2C LCD // MakeMindz.com | Intermediate Series #include <Wire.h> #include <RTClib.h> #include <LiquidCrystal_I2C.h> // LCD address is usually 0x27 or 0x3F // Change if your LCD does not display text LiquidCrystal_I2C lcd(0x27, 16, 2); RTC_DS3231 rtc; // For DS1307, replace above with: RTC_DS1307 rtc; void setup() { lcd.init(); lcd.backlight(); if (!rtc.begin()) { lcd.print("RTC not found!"); while (1); } // Set RTC to compile time (run once, then comment out) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // After first upload, comment above and re-upload } void loop() { DateTime now = rtc.now(); // Row 1: Time — HH:MM:SS lcd.setCursor(0, 0); lcd.print("Time: "); printTwoDigits(now.hour()); lcd.print(":"); printTwoDigits(now.minute()); lcd.print(":"); printTwoDigits(now.second()); // Row 2: Date — DD/MM/YYYY lcd.setCursor(0, 1); lcd.print("Date: "); printTwoDigits(now.day()); lcd.print("/"); printTwoDigits(now.month()); lcd.print("/"); lcd.print(now.year()); delay(1000); // Update every 1 second } // Helper: print leading zero for single digits void printTwoDigits(int num) { if (num < 10) lcd.print("0"); lcd.print(num); }
8Try the Simulation
🎮 Try it Without Hardware
Run the full clock simulation in Tinkercad — watch the LCD display tick in real time right in your browser.
9Features
✅ Real-time hours, minutes, seconds
✅ Day, month, and year display
✅ Time saved after power loss
✅ Clear 16×2 LCD readout
✅ I2C reduces wiring complexity
✅ Beginner and classroom friendly
10Possible Upgrades
Add alarm function with a piezo buzzer
Display temperature (DS3231 has a built-in sensor)
Bluetooth time synchronization via HC-05
IoT clock with NTP auto time-sync (ESP8266/ESP32)
Add push buttons to manually set/adjust time
Data logging with an SD card module
11Learning Outcomes
📡 I2C communication protocol
🕐 RTC module interfacing
🔢 Time formatting and display logic
📟 16×2 LCD interfacing
⏱ Embedded timing concepts
🔋 Battery-backed hardware design
Comments
Post a Comment