← All parts

DS1307

DS1307

RTC

DS1307 I2C real-time clock (8-pin DIP) with battery backup and 1Hz/SQW output.

In stock

Specifications

0

No specs listed.

Pinout

8
PinNameFunctionsNotes
1X1
32.768kHz crystal
2X2
32.768kHz crystal
3VBAT
POWER
Backup battery +
4GND
GND
Ground
5SDA
I2C
I2C data
6SCL
I2C
I2C clock
7SQW/OUT
GPIO
Square-wave / output
8VCC
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

PinArduino Uno R3ESP32 DevKitC (WROOM-32)Notes
VCC+5V5VDS1307 needs ~5 V for reliable I2C (not a 3.3 V part)
GNDGNDGND
SDAA4/SDAGPIO215 V logic - level-shift for the 3.3 V ESP32
SCLA5/SCLGPIO22

Typical uses

  • Basic timekeeping with battery backup
  • Scheduling and timestamps where +/-2 ppm is not needed

Related parts

3