Overview
The PCF8523 is a low-power real-time clock (RTC) module that communicates over I2C. This module is ideal for applications requiring accurate timekeeping, even when the main processor like the ESP32 is powered off.
This report explains how to:
-
Wire the PCF8523 to an ESP32
-
Set up the Arduino IDE
-
Write C-style code to initialize, read, and set time
-
Use both a library-based and raw I2C approach
1. Hardware Requirements
-
ESP32 development board (e.g., DevKit v1, WROOM, etc.)
-
PCF8523 RTC module
-
CR1220 or CR2032 battery (for backup power)
-
Jumper wires
-
Breadboard (optional)
2. Wiring (ESP32 and PCF8523)
The ESP32 uses custom I2C pins, so you’ll define these in code. Default I2C pins are usually:
| PCF8523 Pin | ESP32 Pin (default) |
|---|---|
| VCC | 3.3V (⚠️ Not 5V) |
| GND | GND |
| SDA | GPIO21 |
| SCL | GPIO22 |
⚠️ The ESP32 is a 3.3V device. Ensure your PCF8523 module supports 3.3V, or use a level shifter if needed.
3. Arduino IDE Setup
Step 1: Board Setup
-
Install ESP32 board support via the Board Manager
-
Go to File > Preferences → Add the following to “Additional Board URLs”:
Step 2: Install Required Libraries
-
Open Sketch > Include Library > Manage Libraries
-
Install Adafruit RTClib (supports PCF8523)
4. Example Code (with ESP32 Pin Definition)
A. Initialize and Set Time (C-style Code Using Library)
B. Manually Set a Specific Time
5. Using Raw I2C (Without RTC Library)
For full control, use Wire directly with PCF8523’s I2C address (0x68).
Example: Reading Control Register
6. ESP32 Power Management & Battery Switchover
The PCF8523 features a battery switchover circuit, ensuring it keeps time even when ESP32 is off. You can control power mode using:
-
Register
0x10→ Battery switch-over mode -
rtc.lostPower()to detect brownouts
You can also write to these registers manually via I2C for fine-grained power control.
7. Notes & Best Practices
-
✅ Use a coin cell battery for backup power
-
✅ Use a multimeter to verify your SDA/SCL voltage levels
-
⚠️ Do not power the PCF8523 module with 5V when using an ESP32
-
⚙️ Alarms and timers require manual I2C programming (not supported in Adafruit RTClib)







