กลับไปหน้ารวมไฟล์
rtcds3231-with-1602-lcd-i2c-a5603f.md

HOW IT BEGAN

I have only been using Arduino for about 2 months now. I bought a Keyestudio starter kit and I couldn't get Project 31: DS1302 Real Time Clock Module to work so I tried using a RTC DS3231. I wanted to be able to do a basic thing like print the time and date on a 1602 LCD i2C screen. I tried many sites and different code but I couldn't get it to work. After about 5 weeks I came across a YouTube video and visited the links provided. The code worked so I decided to publish this as my second project.

NEXT STEPS

This whole process made me realize that I need to start paying more attention to the Arduino code and start learning it. I want to be able to manipulate the code more.

OBSTACLES/OPEN TO SUGGESTIONS

  • I haven't figured out how to set the time and date with this sketch. I have previously used a Set Time sketch to set the time and date for a basic RTC sketch, but it didn't work here. The time I set on the clock reset to zero here. I see a (0h) code in the code so I guess it has something to do with that.
  • The LCD screen blinks when the time changes.
  • No schematic. These parts don't exist on Fritzing so I didn't make the schematic.

🛠️ เจาะลึกเบื้องหลังการทำงาน (Deep Dive / Technical Analysis)

The internal millis() counter on an Arduino Uno relies on a microscopic, cheap ceramic resonator. It will physically drift 5 to 10 minutes out of sync within a week because of room temperature fluctuations alone. The RTC DS3231 with 1602 LCD I2C completely abandons the Uno's timer architecture! It queries a completely external, temperature-compensated crystal silicon matrix (DS3231) specifically powered by a secondary physical coin-cell battery, guaranteeing absolute second-by-second accuracy for decades!

Compressing The I2C Wire Matrix (SDA / SCL)

This project requires driving TWO completely separate hardware components (The RTC and the LCD).

  1. The incredibly powerful capability of the I2C Bus is chaining components!
  2. You do not need 8 wires. Both the RTC and the LCD literally share the exact same two pins: A4 (SDA - Data) and A5 (SCL - Clock)!
  3. The Multi-Device Addressing Trap: How does the Uno talk to the Clock without the Screen freaking out? Every I2C chip has a permanent, physical hexadecimal address burned into its silicon at the factory!
    • RTC DS3231 is at Address: 0x68.
    • LCD Screen is at Address: 0x27 (or 0x3F).

Interrogating the Epoch Library Array (RTClib.h)

The code utilizes the <RTClib.h> driver interface!

  • You extract the explicit massive integer representations continuously!
DateTime now = rtc.now(); // Query the massive battery-backed hardware matrix!

lcd.setCursor(0, 0); // Jump to line 1
lcd.print(now.year()); lcd.print('/'); 
lcd.print(now.month()); lcd.print('/'); 
lcd.print(now.day()); // Output flawless date parsing!

lcd.setCursor(0, 1); // Jump to line 2
// Complex formatting: If hour is '7', print '07' recursively!
if (now.hour() < 10) { lcd.print((char)'0'); } 
lcd.print(now.hour()); 
  • By dropping the massive timestamp querying loop down to a rigid 1-second delay(), the graphical display dynamically ticks completely flawlessly identical to an absolute commercial digital dashboard!

Time-Keeping Component Needs

  • Arduino Uno/Nano (Standard execution speeds are perfectly sufficient).
  • DS3231 Real-Time Clock Module (Must include the physical CR2032 Lithium coin cell battery! Without the battery, the instant you unplug the USB cable, the clock chemically forgets the date entirely and resets to 1970!).
  • Standard 16x2 I2C Display Module.

ข้อมูล Frontmatter ดั้งเดิม

title: "RTCDS3231 with 1602 LCD I2C"
description: "Print text, date and time with RTC DS3213 and 1602 LCD I2C"
author: "Tishin"
category: ""
tags:
  - "1602 lcd i2c"
  - "ds3213"
  - "text time date"
views: 24012
likes: 2
price: 1499
difficulty: "Easy"
components:
  - "1x Arduino UNO"
  - "1x 1602 I2C Module"
  - "1x RTC DS3231"
tools: []
apps:
  - "1x Arduino Web Editor"
  - "1x circuito.io"
  - "1x Arduino IDE"
downloadableFiles:
  - "https://create.arduino.cc/editor/Tishin/19bff325-d3af-4c21-ade3-e0081446e900/preview"
documentationLinks: []
passwordHash: "ce770fd17dff09bf9c56eaebd80d5bd1beea262dc4f60aa4f20550e020da8073"
encryptedPayload: "U2FsdGVkX1/Ez+gFqNON++B+aSk1a/5ZxNFGUoNJp7oqS/d+fAuwbGmmEQpl3oeHDPaRc9x/VuDMLEQxA3OfmRg1HscA4Xcuzo4uY8DZL2Pd0qbYedij2hf5ztjd5NsmfQPNlGp18XyCJ7WogYYhmg=="
seoDescription: "Display date and time using RTC DS3231 and 1602 LCD I2C with Arduino."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/rtcds3231-with-1602-lcd-i2c-a5603f_cover.jpg"
lang: "en"