

The DS1307 Real-Time Clock (RTC) module, manufactured by Baramee, is a timekeeping device designed to maintain accurate time and date information. It operates independently of the main system power, thanks to an onboard backup battery. The DS1307 is widely used in applications requiring precise timekeeping, such as data logging, alarms, and scheduling systems.








The DS1307 RTC module is a low-power, I2C-based timekeeping device. Below are its key technical details:
The DS1307 RTC module has 8 pins. The table below describes each pin:
| Pin Number | Pin Name | Description |
|---|---|---|
| 1 | X1 | External 32.768 kHz crystal oscillator input |
| 2 | X2 | External 32.768 kHz crystal oscillator output |
| 3 | VBAT | Backup battery input (connect to a 3V coin cell for power backup) |
| 4 | GND | Ground connection |
| 5 | SDA | Serial Data Line for I2C communication |
| 6 | SCL | Serial Clock Line for I2C communication |
| 7 | NC | Not connected (leave unconnected or use as a mechanical support point) |
| 8 | VCC | Main power supply input (4.5V to 5.5V) |
Below is an example of how to use the DS1307 RTC module with an Arduino UNO:
#include <Wire.h>
#include <RTClib.h>
// Create an RTC_DS1307 object
RTC_DS1307 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");
while (1); // Halt the program if RTC is not found
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running, 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 date and 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 Not Detected:
Time Resets After Power Loss:
Incorrect Time or Date:
rtc.adjust() function to set the correct time and date.I2C Address Conflict:
Q: Can the DS1307 operate without a backup battery?
A: Yes, but it will lose timekeeping functionality during power outages.
Q: What is the maximum length of the I2C bus?
A: The I2C bus length should typically not exceed 1 meter to ensure reliable communication.
Q: Can I use a different crystal oscillator frequency?
A: No, the DS1307 is designed to work specifically with a 32.768 kHz crystal oscillator.
Q: How much data can I store in the DS1307's RAM?
A: The DS1307 provides 56 bytes of non-volatile RAM for user data storage.