PCF8563 Real-Time Clock (RTC)

View on Amazon
Overview
About PCF8563 Real-Time Clock (RTC)
The PCF8563 is a CMOS-based real-time clock (RTC) and calendar designed for ultra-low power applications. It provides complete timekeeping functions, including year, month, day, weekday, hours, minutes, and seconds, along with a century flag. Unlike the DS1307, the PCF8563 operates over a wider voltage range (1.0V – 5.5V) and offers lower power consumption, making it ideal for battery-powered applications.
⚡ Key Features
- Low Power Consumption – Optimized for battery-operated devices.
- Wide Voltage Range – Operates from 1.0V to 5.5V, broader than DS1307.
- Programmable Clock Output – Provides flexible timing and clock generation.
- Alarm & Timer Functions – Supports event triggering and scheduling.
- Integrated Oscillator Capacitor – Reduces external component requirements.
With its power efficiency and advanced features, the PCF8563 is a great choice for portable, low-power, and precision timekeeping applications. 🚀
Get Your PCF8563
💡 Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
PCF8563 Specifications
Complete technical specification details for PCF8563 Real-Time Clock (RTC)
📊 Technical Parameters
PCF8563 Pinout
The PCF8563 has 8 pins including I²C interface, oscillator connections, and optional interrupt/clock outputs.
Visual Pinout Diagram

Pin Types
Quick Tips
Object],[object Object],[object Object]
32.768 kHz crystal (not included on basic modules),Integrated oscillator capacitor (no external caps needed)
and timer functions with interrupt capability,Century flag for year tracking
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 OSCI | Oscillator | Oscillator input. Connect to one terminal of 32.768 kHz crystal. | Crystal capacitor integrated internally. |
2 OSCO | Oscillator | Oscillator output. Connect to other terminal of 32.768 kHz crystal. | |
3 INT | Interrupt | Interrupt output (open-drain, active low). Triggers on alarm or timer events. | Requires external pull-up resistor (~10kΩ). |
4 VDD | Power | Power supply input (1.0V-5.5V). Wide voltage range for battery operation. | Ultra-low power consumption. |
5 VSS | Power | Ground connection. Connect to system ground. | |
6 SDA | I2C | I²C Serial Data Line. Bidirectional data communication. | Connect to ESP32 GPIO 21 (default SDA). |
7 SCL | I2C | I²C Serial Clock Line. Clock signal for I²C communication. | Connect to ESP32 GPIO 22 (default SCL). |
8 CLKOUT | Clock Output | Programmable clock output. Configurable frequency for external devices. | Optional - can provide clock signal to other components. |
Wiring PCF8563 to ESP32
To interface the PCF8563 with an ESP32, connect VDD to 3.3V or 5V, VSS to ground, SDA to GPIO 21, SCL to GPIO 22, and attach a 32.768 kHz crystal between OSCI and OSCO.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| PCF8563 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VDD Required | 3.3V | Power supply. Use 3.3V for battery-powered applications. | |
2 VSS Required | GND | Ground connection. | |
3 SDA Required | GPIO 21 | I²C data line. Requires pull-up resistor (4.7kΩ typical). | |
4 SCL Required | GPIO 22 | I²C clock line. Requires pull-up resistor (4.7kΩ typical). | |
5 OSCI/OSCO Required | 32.768 kHz Crystal | Connect 32.768 kHz crystal between OSCI and OSCO pins. | |
6 INT Optional | Optional GPIO | Interrupt output for alarm/timer events. Requires 10kΩ pull-up. | |
7 CLKOUT Optional | Optional | Programmable clock output for external devices. |
Object]
4.7kΩ pull-up resistors on SDA and SCL lines
kHz crystal required for accurate timekeeping
Object]
pin is open-drain - requires external pull-up resistor (~10kΩ)
initial time after first power-on or battery replacement
power consumption than DS1307 - ideal for portable projects
modules include crystal and battery holder
PCF8563 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The PCF8563 RTC module displays a constant time or advances time incorrectly.
Possible causes include insufficient power supply, incorrect wiring, or a defective module.
Solution: Ensure that the module is connected to a stable power source, with VCC connected to 3.3V or 5V (depending on your module) and GND to ground. Verify that the SDA and SCL pins are correctly connected to the appropriate I2C pins on the microcontroller. If the problem persists, consider replacing the PCF8563 module, as some units may be faulty.
Issue: The PCF8563 module displays incorrect or corrupted date and time information.
Possible causes include improper initialization, incorrect data retrieval methods, or communication errors.
Solution: Ensure that the RTC is properly initialized in your code, setting the correct time and date during setup. Use reliable libraries and functions to set and retrieve time data. Verify that the communication between the microcontroller and the RTC is functioning correctly, and consider implementing error-checking mechanisms to detect and handle communication issues.
Issue: The PCF8563 module becomes excessively hot during operation.
Possible causes include incorrect power connections, short circuits, or defective components.
Solution: Double-check all power connections to ensure they are correct, with VCC connected to the appropriate voltage and GND to ground. Inspect the module and wiring for any signs of short circuits or solder bridges. If the module continues to overheat, it may be defective and should be replaced.
Issue: The PCF8563 RTC loses track of time after a power cycle.
Possible causes include a missing or depleted backup battery, or incorrect wiring of the backup power supply.
Solution: Install a backup battery (e.g., a CR2032 coin cell) to the appropriate pins to maintain timekeeping during power loss. Ensure that the battery is fresh and properly connected. Verify that the module is configured to switch to the backup battery when the main power is unavailable.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
PCF8563 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include <Rtc_Pcf8563.h>
Rtc_Pcf8563 rtc;
void setup() {
Serial.begin(9600);
Wire.begin(21, 22); // SDA: GPIO21, SCL: GPIO22
rtc.initClock();
rtc.setDate(4, 12, 2023); // DD, MM, YYYY
rtc.setTime(14, 30, 0); // HH, MM, SS
}
void loop() {
Serial.print("Time: ");
Serial.print(rtc.getHour());
Serial.print(":");
Serial.print(rtc.getMinute());
Serial.print(":");
Serial.println(rtc.getSecond());
Serial.print("Date: ");
Serial.print(rtc.getDay());
Serial.print("/");
Serial.print(rtc.getMonth());
Serial.print("/");
Serial.println(rtc.getYear());
delay(1000);
}Rtc_Pcf8563 library and the specified pin configuration (SDA: GPIO21, SCL: GPIO22). In the setup(), the RTC is initialized and the date and time are set. The loop() retrieves and prints the current time and date to the Serial Monitor every second.#include <stdio.h>
#include "driver/i2c.h"
#include "pcf8563.h"
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
void app_main(void) {
i2c_config_t i2c_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 100000
};
i2c_param_config(I2C_NUM_0, &i2c_config);
i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
pcf8563_init(I2C_NUM_0);
pcf8563_set_datetime(2023, 12, 4, 14, 30, 0);
while (1) {
pcf8563_datetime_t now;
pcf8563_get_datetime(&now);
printf("Time: %02d:%02d:%02d\n", now.hour, now.minute, now.second);
printf("Date: %04d/%02d/%02d\n", now.year, now.month, now.day);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}pcf8563_set_datetime(). The current time and date are fetched using pcf8563_get_datetime() and printed to the console every second.i2c:
sda: GPIO21
scl: GPIO22
time:
- platform: pcf8563
id: pcf8563_time
update_interval: 1s
sensor:
- platform: custom
lambda: |-
auto my_sensor = new PCF8563Sensor(id(pcf8563_time));
return {my_sensor};
sensors:
- name: "PCF8563 Date and Time"time platform fetches time and date information at 1-second intervals, and a custom sensor displays the data in a human-readable format.platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200main.cpp
#include <Wire.h>
#include <Rtc_Pcf8563.h>
Rtc_Pcf8563 rtc;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA: GPIO21, SCL: GPIO22
rtc.initClock();
rtc.setDate(4, 12, 2023); // DD, MM, YYYY
rtc.setTime(14, 30, 0); // HH, MM, SS
}
void loop() {
Serial.print("Time: ");
Serial.print(rtc.getHour());
Serial.print(":");
Serial.print(rtc.getMinute());
Serial.print(":");
Serial.println(rtc.getSecond());
Serial.print("Date: ");
Serial.print(rtc.getDay());
Serial.print("/");
Serial.print(rtc.getMonth());
Serial.print("/");
Serial.println(rtc.getYear());
delay(1000);
}setup(), while the loop() fetches and prints the current time and date every second.from machine import I2C, Pin
import time
# PCF8563 I2C address
PCF8563_ADDRESS = 0x51
def bcd_to_decimal(bcd):
return (bcd >> 4) * 10 + (bcd & 0x0F)
def decimal_to_bcd(decimal):
return ((decimal // 10) << 4) | (decimal % 10)
def set_time(i2c, year, month, day, hour, minute, second):
data = [decimal_to_bcd(second), decimal_to_bcd(minute), decimal_to_bcd(hour),
0, decimal_to_bcd(day), decimal_to_bcd(month), decimal_to_bcd(year - 2000)]
i2c.writeto_mem(PCF8563_ADDRESS, 0x02, bytes(data))
def get_time(i2c):
data = i2c.readfrom_mem(PCF8563_ADDRESS, 0x02, 7)
second = bcd_to_decimal(data[0] & 0x7F)
minute = bcd_to_decimal(data[1] & 0x7F)
hour = bcd_to_decimal(data[2] & 0x3F)
day = bcd_to_decimal(data[3] & 0x3F)
month = bcd_to_decimal(data[5] & 0x1F)
year = bcd_to_decimal(data[6]) + 2000
return year, month, day, hour, minute, second
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Set initial time
set_time(i2c, 2023, 12, 4, 14, 30, 0)
# Loop to read time
while True:
year, month, day, hour, minute, second = get_time(i2c)
print(f"Time: {hour:02}:{minute:02}:{second:02}, Date: {year:04}/{month:02}/{day:02}")
time.sleep(1)set_time() function initializes the RTC with the specified time and date, while the get_time() function reads and decodes the current time and date. In the loop, the script continuously fetches and prints the current time and date every second.Wrapping Up PCF8563
The ESP32 PCF8563 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.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the PCF8563 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the PCF8563? Check out these similar sensors that might fit your project needs.

DS1302 Real-Time Clock (RTC)
The DS1302 is a cost-effective real-time clock module designed for accurate timekeeping. It operates on a 3-wire serial protocol and...

DS1307 Real-Time Clock (RTC)
The DS1307 is a widely used real-time clock module with I2C communication. It supports leap year compensation, battery-backed operation, and...

DS3231 / AT24C32 Real-Time Clock (RTC)
The DS3231 is a highly accurate I²C real-time clock with an integrated temperature-compensated crystal oscillator, providing precise...





