Skip to content

Real Time Clock

github-actions[bot] edited this page Dec 3, 2025 · 3 revisions

⏰ Real-Time Clock

A Real-Time Clock (RTC) module keeps accurate time, even without internet access.

Most common RTC modules with I²C will work. Good starting points include the DS3231 (e.g. this) and the DS1307 (e.g. this).

✅ Supported types

📌 Schematics

DS1307 schema

┌─────┐
│ VCC ├─ +5 V DC
│ GND ├─ 0 V DC
|     |
│ SCL ├─ I²C SCL
│ SDA ├─ I²C SDA
└─────┘

DS3231 schema

┌─────┐
│ VCC ├─ +3.3 V DC
│ GND ├─ 0 V DC
|     |
│ SCL ├─ I²C SCL
│ SDA ├─ I²C SDA
|     |
│ INT ├─ RTC INT
└─────┘

DS3232 schema

┌─────┐
│ VCC ├─ +3.3 V DC
│ GND ├─ 0 V DC
|     |
│ SCL ├─ I²C SCL
│ SDA ├─ I²C SDA
|     |
│ INT ├─ RTC INT
└─────┘

PCF8563 schema

┌─────┐
│ VCC ├─ +3.3 V DC
│ GND ├─ 0 V DC
|     |
│ SCL ├─ I²C SCL
│ SDA ├─ I²C SDA
|     |
│ INT ├─ RTC INT
└─────┘

ESP32 schema

┌────────────────┐
│            VIN ├─ +5 V DC
│            3V3 ├─ +3.3 V DC
│            GND ├─ 0 V DC
│                │
│            SCL ├─ I²C SCL
│            SDA ├─ I²C SDA
│                │
│  Digital input ├─ RTC INT
└────────────────┘

Logic level shifter schema

   0 V DC ────────┬──────── 0 V DC
+3.3 V DC ────┐   │   ┌──── +5 V DC
           ┌──┴───┴───┴──┐
           │ VCC GND VCC │
 I²C SCL  ─┤     ──►     ├─ I²C SCL
 I²C SDA  ─┤     ◄─►     ├─ I²C SDA
 RTC INT  ─┤     ◄──     ├─ RTC INT
           └─────────────┘

↔️ Logic level shifter

Most RTC modules are 3.3 V compatible, but some variants use higher logic levels (e.g. 5 V). In those cases, a logic level shifter is required to ensure safe communication with the ESP32. Make sure it is suited for I²C signals, like TXS0104E (e.g. this).

🔧 Configuration

I²C SCL

Serial clock for I²C communication.

Any I²C SCL pin can be used.

Configure in secrets.h:

#define PIN_SCL 1 // I²C SCL

I²C SDA

Bidirectional data line for I²C.

Any I²C SDA pin can be used.

Configure in secrets.h:

#define PIN_SDA 2 // I²C SDA

RTC INT

Interrupt signal from the RTC module.

Optional to connect.

Any digital input pin that are also RTC-capable can be used.

Configure in secrets.h:

#define PIN_INT 3 // RTC INT

🧩 Extension

Using the RTC extension, the clock will automatically sync during during startup.

Check out the RTC extension for more info.

📝 Templates

DS1307

Configure in secrets.h:

#define RTC_DS1307

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA

Important

Logic level shifter required.

Warning

Incompatible with IKEA Frekvens due to the lack of a 5 V power supply.

DS3231

Configure in secrets.h:

#define RTC_DS3231

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA
#define PIN_INT 3 // RTC INT

DS3232

Configure in secrets.h:

#define RTC_DS3232

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA
#define PIN_INT 3 // RTC INT

PCF8563

Configure in secrets.h:

#define RTC_PCF8563

#define PIN_SCL 1 // I²C SCL
#define PIN_SDA 2 // I²C SDA
#define PIN_INT 3 // RTC INT

🔗 Resources

External links for deeper exploration — provided for reference only and with no formal connection to this project.

Clone this wiki locally