

A Real-Time Clock (RTC) module is a device designed to keep track of the current time and date, even when the main power supply is disconnected. It achieves this by using a small backup battery to maintain timekeeping functionality. RTC modules are commonly used in applications where accurate timekeeping is essential, such as data logging, alarms, scheduling, and real-time systems.








Below are the general technical specifications for a typical RTC module, such as the DS3231 or DS1307:
The following table describes the pinout of a typical RTC module:
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply input (3.3V or 5V). |
| 2 | GND | Ground connection. |
| 3 | SDA | Serial Data Line for I2C communication. |
| 4 | SCL | Serial Clock Line for I2C communication. |
| 5 | SQW/OUT | Square Wave Output (optional, used for alarms or clock signals). |
| 6 | BAT | Backup battery input (connects to a CR2032 battery to maintain timekeeping). |
RTClib for Arduino).Below is an example of how to use the RTC module with an Arduino UNO using the RTClib library:
#include <Wire.h>
#include <RTClib.h>
// Create an RTC object
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud
Wire.begin(); // Initialize I2C communication
if (!rtc.begin()) {
Serial.println("Couldn't find RTC module. Check connections!");
while (1); // Halt execution if RTC is not found
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, setting the time...");
// Set the RTC to the current date and time
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now(); // Get the current date and time
// Print the current time to the Serial Monitor
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000); // Wait for 1 second before updating
}
RTC Module Not Detected
Incorrect Time Displayed
rtc.adjust() function to set the correct time.Backup Battery Drains Quickly
Interference on I2C Lines
Q: Can I use the RTC module without a backup battery?
A: Yes, but the time will reset whenever the main power is disconnected.
Q: How accurate is the RTC module?
A: The DS3231 is highly accurate (±2 ppm), while the DS1307 is less accurate (±20 ppm).
Q: Can I use multiple RTC modules on the same I2C bus?
A: Yes, as long as each module has a unique I2C address. However, most RTC modules have a fixed address, so this may require additional configuration.
Q: How do I know if the backup battery is low?
A: Some RTC modules, like the DS3231, have a status register that can indicate low battery voltage.
By following this documentation, you can effectively integrate an RTC module into your projects for reliable timekeeping functionality.