ESP32 DS1307 Real-Time Clock (RTC)

DS1307 Real-Time Clock (RTC) image

DS1307

Protocol: I2C

Overview

The DS1307 is a widely used real-time clock module with I2C communication. It supports leap year compensation, battery-backed operation, and 56 bytes of user-accessible SRAM, making it ideal for embedded systems and low-power applications.

About DS1307 Real-Time Clock (RTC)

The DS1307 is a widely used real-time clock (RTC) module designed to maintain accurate timekeeping, including automatic leap year compensation. Unlike the DS1302, it communicates via I²C, simplifying integration with ESP32, Arduino, and other microcontrollers.

Key Features

  • Real-Time Clock Functionality – Tracks seconds, minutes, hours, day, date, month, and year.
  • I²C Communication – Easier integration than 3-wire serial RTCs like the DS1302.
  • 56-Byte Battery-Backed SRAM – Stores small user data for embedded applications.
  • Battery Backup Support – Maintains timekeeping during power loss (no trickle charger like DS1302).

With its I²C interface and reliable backup capabilities, the DS1307 is an excellent choice for data loggers, automation systems, and real-time event tracking. 🚀

🔗 Looking for a different RTC? Check out the DS1302 for a 3-wire alternative with trickle charging.

Where to Buy

DS1307 Real-Time Clock (RTC)

Starting from

2.50$ per unit

Amazon com
Amazon.com Ships worldwide
View Price
Amazon de
Amazon.de Ships to EU
View Price
Aliexpress
AliExpress Best value
View Price

Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.

Technical Specifications

Timekeeping Range Seconds to Year (up to 2100)
Power Supply Voltage 4.5V to 5.5V (VCC), 2.0V to 3.5V (VBAT)
Backup Battery Current <500 nA at 3.0V
Interface I2C (400 kHz)
Data Storage 56 bytes of battery-backed SRAM
Clock Accuracy Determined by external crystal
Operating Temperature 0°C to +70°C (Commercial), -40°C to +85°C (Industrial)

Pinout Configuration

The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32.

The DS1307 pinout is as follows:

  • VCC: Primary power supply input (5V).
  • GND: Ground connection.
  • SDA: Serial Data for I2C communication.
  • SCL: Serial Clock for I2C communication.
  • X1: Connection for 32.768 kHz crystal oscillator.
  • X2: Connection for 32.768 kHz crystal oscillator.
  • VBAT: Battery backup power input (3V).

Wiring with ESP32

To use the DS1307 with a microcontroller like Arduino or ESP32, connect VCC to a 5V power supply, GND to ground, SDA to the microcontroller's I2C data pin, and SCL to the I2C clock pin. Connect a 32.768 kHz crystal to X1 and X2, and attach a 3V coin cell battery to VBAT to maintain timekeeping during power loss.

Troubleshooting Guide

Common Issues

⚠️ Incorrect Time or Date Displayed

⏰ RTC Not Advancing Time Correctly

🔌 Communication Issues with Microcontroller

🔄 Time Resets After Power Loss

Debugging Tips

🔍 Serial Monitor

⚡ Voltage Checks

Code Examples

Arduino Example

C++
🔧

ESP-IDF Example

C++
🏠

ESPHome Example

YAML
🛠️

PlatformIO Example

C++
🐍

MicroPython Example

Python

Conclusion

The ESP32 DS1307 Real-Time Clock (RTC) is a powerful RTC sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.

For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.

Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.