Project Overview
The "RTCDS3231 with 1602 LCD I2C" project is a fundamental building block for anyone creating precision timekeeping devices. It integrates the high-accuracy DS3231 Real-Time Clock (RTC) with a 16x2 LCD display using the I2C protocol. This setup significantly reduces the number of wires required compared to a standard parallel LCD interface (requiring only 4 wires: VCC, GND, SDA, and SCL). This project is ideal for creating digital clocks, attendance systems, or data loggers that require timestamped events with minimal hardware overhead.
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.
Technical Working Principle
- I2C Communication: Both the DS3231 and the LCD 1602 (via an I2C adapter) communicate over the Inter-Integrated Circuit (I2C) bus. This enables multiple devices to share the same two signal pins (SDA/SCL) on the Arduino UNO.
- DS3231 High Precision: Unlike the common DS1302, the DS3231 is an extremely accurate RTC with an integrated Temperature-Compensated Crystal Oscillator (TCXO). This ensures that the clock remains accurate within seconds per month, even with temperature fluctuations that would cause other RTCs to drift.
- Battery Backup: The RTC module typically includes a CR2032 coin cell slot, allowing it to maintain the correct time even when the main Arduino power is disconnected.
Engineering Insights & Optimization
- Preventing "Blinking" Display: A common issue reported in this project is the LCD screen blinking. This usually happens because the code is using
lcd.clear()inside the main loop. Instead, it is better to only overwrite the changed characters or uselcd.setCursor(0, 0)and overwrite the previous string with a fixed-length string to prevent flickering. - Setting the Time: Setting the time can be done once in the
void setup()using thertc.adjust(DateTime(F(__DATE__), F(__TIME__)));function in the RTClib. This sets the clock to the exact time the code was compiled. After uploading once, that line should be commented out and the code re-uploaded to prevent the clock from resetting every time the Arduino reboots. - Voltage Levels: Both the DS3231 and the LCD I2C module operate comfortably at 5V, provided by the Arduino UNO. However, ensure that the I2C address for the LCD (usually
0x27or0x3F) is correctly identified using an I2C scanner sketch if the display doesn't show anything.