The DS1307 RTC (Real-Time Clock) is a low-power, full binary-coded decimal (BCD) clock/calendar with 56 bytes of NV SRAM. It communicates with a microcontroller via the I2C protocol and is used to keep track of time even when the main device is powered off. The Wokwi Compatible version is designed for easy integration with the Wokwi simulation platform.
Parameter | Value |
---|---|
Operating Voltage | 4.5V to 5.5V |
Operating Current | 1.5mA (typical) |
Timekeeping Current | 500nA (typical) |
Interface | I2C (2-wire) |
Clock Accuracy | ±2ppm from 0°C to +40°C |
NV SRAM | 56 bytes |
Temperature Range | -40°C to +85°C |
Pin | Name | Description |
---|---|---|
1 | GND | Ground |
2 | VCC | Power Supply (4.5V to 5.5V) |
3 | SCL | Serial Clock Line (I2C) |
4 | SDA | Serial Data Line (I2C) |
5 | SQW/OUT | Square Wave/Output Driver (Open Drain) |
6 | NC | No Connection |
7 | NC | No Connection |
8 | VBAT | Battery Backup Input (3V Lithium Cell) |
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Set 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);
}
rtc.adjust()
function.By following this documentation, users should be able to effectively integrate and utilize the DS1307 RTC in their projects, ensuring accurate timekeeping and reliable performance.