The TINY RTC is a compact real-time clock (RTC) module designed to keep track of the current time and date. It is widely used in microcontroller projects to maintain accurate timekeeping, even when the main power supply is disconnected. This is achieved through the use of a backup battery, which ensures continuous operation. The module is based on the DS1307 RTC chip and is commonly paired with microcontrollers like Arduino, Raspberry Pi, and others.
The TINY RTC module is built around the DS1307 RTC chip and includes additional components like a backup battery and pull-up resistors for I2C communication. Below are the key technical details:
The TINY RTC module typically has a 4-pin interface for I2C communication. Below is the pinout:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply input (5V DC) |
2 | GND | Ground connection |
3 | SDA | Serial Data Line for I2C communication |
4 | SCL | Serial Clock Line for I2C communication |
Connect the Module:
VCC
pin to the 5V output of your microcontroller.GND
pin to the ground of your microcontroller.SDA
pin to the I2C data line of your microcontroller.SCL
pin to the I2C clock line of your microcontroller.Install the Backup Battery:
Include the Required Libraries:
RTClib
library, which provides easy-to-use functions for the DS1307.Write and Upload Code:
#include <Wire.h>
#include <RTClib.h>
// Create an RTC object
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600); // Initialize serial communication
Wire.begin(); // Initialize I2C communication
if (!rtc.begin()) {
Serial.println("Couldn't find RTC. Check connections!");
while (1); // Halt execution if RTC is not found
}
if (!rtc.isrunning()) {
Serial.println("RTC is not running. Setting the time...");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// Sets the RTC to the date & time of compilation
}
}
void loop() {
DateTime now = rtc.now(); // Get the current time and date
// Print the current time and date 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
}
0x68
) if using multiple I2C devices.RTC Not Detected:
SDA
and SCL
lines.Incorrect Time or Date:
rtc.adjust()
function to set the correct time and replace the battery if necessary.I2C Communication Errors:
RTC Stops Keeping Time After Power Loss:
Q: Can the TINY RTC module work with 3.3V microcontrollers?
A: The DS1307 chip requires a 5V power supply. Use a level shifter for I2C lines if interfacing with a 3.3V microcontroller.
Q: How long does the backup battery last?
A: A typical CR2032 battery can last for several years, depending on usage and environmental conditions.
Q: Can I use the TINY RTC module to store custom data?
A: Yes, the DS1307 includes 56 bytes of non-volatile RAM that can be used to store user data.
Q: What is the default I2C address of the TINY RTC module?
A: The default I2C address is 0x68
.