← All parts
DS1307
DS1307
RTC
DS1307 I2C real-time clock (8-pin DIP) with battery backup and 1Hz/SQW output.
In stock
Specifications
0No specs listed.
Pinout
8| Pin | Name | Functions | Notes |
|---|---|---|---|
| 1 | X1 | — | 32.768kHz crystal |
| 2 | X2 | — | 32.768kHz crystal |
| 3 | VBAT | POWER | Backup battery + |
| 4 | GND | GND | Ground |
| 5 | SDA | I2C | I2C data |
| 6 | SCL | I2C | I2C clock |
| 7 | SQW/OUT | GPIO | Square-wave / output |
| 8 | VCC | POWER | Supply |
Interactive pinout
Highlight:
DS1307
Click a pin to copy its name · tap a tag above to spotlight a bus.
Starter code
Community starter examples — minimal, unofficial, and provided to get you wiring fast. Verify against the manufacturer datasheet before relying on them.
Arduino (C++)
Arduino library: RTClib (by Adafruit)
arduino
// DS1307 real-time clock (I2C) — community starter example
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
void setup() {
Serial.begin(115200);
Wire.begin();
if (!rtc.begin()) { Serial.println("DS1307 not found"); while (1) delay(10); }
if (!rtc.isrunning()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.hour()); Serial.print(':'); Serial.print(now.minute()); Serial.print(':');
Serial.println(now.second());
delay(1000);
}MicroPython
MicroPython library: ds1307 (mcauser/micropython-tinyrtc-i2c)
python
# DS1307 RTC (ESP32) — community starter example
# raw I2C register read (BCD); driver: mcauser/micropython-tinyrtc-i2c
from machine import Pin, I2C
import time
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
ADDR = 0x68
def bcd2dec(b): return (b >> 4) * 10 + (b & 0x0F)
while True:
d = i2c.readfrom_mem(ADDR, 0x00, 7)
print("%02d:%02d:%02d" % (bcd2dec(d[2] & 0x3F), bcd2dec(d[1]), bcd2dec(d[0] & 0x7F)))
time.sleep(1)Wiring
| Pin | Arduino Uno R3 | ESP32 DevKitC (WROOM-32) | Notes |
|---|---|---|---|
| VCC | +5V | 5V | DS1307 needs ~5 V for reliable I2C (not a 3.3 V part) |
| GND | GND | GND | |
| SDA | A4/SDA | GPIO21 | 5 V logic - level-shift for the 3.3 V ESP32 |
| SCL | A5/SCL | GPIO22 |
Typical uses
- Basic timekeeping with battery backup
- Scheduling and timestamps where +/-2 ppm is not needed