ESP32 DS1302 Real-Time Clock (RTC)

DS1302 Real-Time Clock (RTC) image

DS1302

Protocol: 3-Wire

Overview

The DS1302 is a cost-effective real-time clock module designed for accurate timekeeping. It operates on a 3-wire serial protocol and supports dual power supplies with a programmable trickle charger, making it suitable for embedded systems, IoT devices, and battery-backed applications.

About DS1302 Real-Time Clock (RTC)

The DS1302 is a low-power real-time clock (RTC) chip capable of maintaining accurate time and date, including leap year compensation up to 2100. It features built-in SRAM storage and a 3-wire serial interface, making it easy to integrate into time-sensitive applications.

Key Features

  • Real-Time Clock Functionality – Tracks seconds, minutes, hours, day, month, and year.
  • Integrated 31-Byte SRAM – Provides small data storage for system use.
  • Dual Power Supply with Trickle Charger – Supports battery backup for continuous operation.
  • 3-Wire Serial Interface – Ensures efficient communication with ESP32, Arduino, and other microcontrollers.

With its battery-backed operation and compact design, the DS1302 is perfect for low-power embedded systems, data loggers, and real-time event tracking. 🚀

Where to Buy

DS1302 Real-Time Clock (RTC)

Starting from

1.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 2.0V to 5.5V
Backup Battery Voltage 2.0V to 5.5V
Power Consumption <300 nA at 2.5V (battery backup mode)
Interface 3-wire serial
Clock Accuracy Determined by external crystal
Data Storage 31 bytes of static RAM
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 DS1302 pinout is as follows:

  • VCC1: Primary power supply input.
  • VCC2: Backup power supply input.
  • SCLK: Serial clock input for communication.
  • I/O: Data input/output pin.
  • RST: Reset input to enable communication.
  • GND: Ground connection.
  • X1: Connection for 32.768 kHz crystal oscillator.
  • X2: Connection for 32.768 kHz crystal oscillator.

Wiring with ESP32

To use the DS1302 with a microcontroller like Arduino or ESP32, connect VCC1 to a 5V power supply, VCC2 to a backup battery or capacitor, GND to ground, SCLK to a GPIO pin for serial clock, I/O to a GPIO pin for data communication, and RST to another GPIO pin for enabling the chip. Ensure proper initialization in the microcontroller firmware.

Troubleshooting Guide

Common Issues

⏰ RTC Not Advancing Time Correctly

⚠️ Incorrect or Corrupted Date and Time Display

🔥 RTC Module Overheating

🔄 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 DS1302 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.