The DS1307 Real Time Clock (RTC) Module is a low-power, full binary-coded decimal (BCD) clock/calendar with 56 bytes of NV SRAM. It provides precise timekeeping with a built-in 32.768 kHz crystal oscillator. Common applications include timekeeping in embedded systems, logging events with timestamps, and maintaining accurate time across power cycles in devices like digital clocks, attendance systems, and data loggers.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (4.5V to 5.5V) |
2 | GND | Ground |
3 | SDA | Serial Data Line for I2C communication |
4 | SCL | Serial Clock Line for I2C communication |
5 | SQW/OUT | Square Wave/Output Driver (Not always used) |
6 | 32K | 32kHz Output (Not always used) |
7 | BAT | Battery Input for Backup |
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
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);
}
Q: How do I set the time on the DS1307 RTC?
A: You can set the time by using the rtc.adjust(DateTime(__DATE__, __TIME__));
function in your setup routine.
Q: What is the life expectancy of the backup battery? A: The battery life depends on the quality of the battery but typically lasts for several years.
Q: Can the DS1307 RTC module work without an Arduino? A: Yes, it can work with any microcontroller that supports I2C communication.
Q: Is it necessary to use a 32.768 kHz crystal with the DS1307? A: The DS1307 RTC module typically comes with a built-in 32.768 kHz crystal. It is crucial for accurate timekeeping and should not be removed or replaced.
For further assistance, consult the datasheet of the DS1307 RTC module or contact technical support.