ESP32 and PCF8563 RTC module example

The PCF8563 is a CMOS Real-Time Clock (RTC) and calendar optimized for low power consumption. A programmable clock output, interrupt output, and voltage-low detector are also provided. All addresses and data are transferred serially via a two-line bidirectional I²C-bus. Maximum bus speed is 400 kbit/s.


  • Provides year, month, day, weekday, hours, minutes, and seconds based on a 32.768 kHz quartz crystal
  • Century flag
  • Clock operating voltage: 1.0 V to 5.5 V at room temperature
  • Low backup current; typical 0.25 μA at VDD = 3.0 V and Tamb = 25 °C
  • 400 kHz two-wire I²C-bus interface (at VDD = 1.8 V to 5.5 V)
  • Programmable clock output for peripheral devices (32.768 kHz, 1.024 kHz, 32 Hz, and 1 Hz)
  • Alarm and timer functions
  • Integrated oscillator capacitor
  • Internal Power-On Reset (POR)
  • I²C-bus slave address: read A3h and write A2h
  • Open-drain interrupt pin


ESP32 Pin Module Pin
3v3  Vcc
22 – SCL SCL
21 – SDA SDA

Parts List

Here are the parts I used

Part name Link
Lolin32 New ESP-32 esp32 Lite V1.0.0 For Rev1 wifi Module + bluetooth board 4MB FLASH
PCF8563 module PCF8563 IIC Real Time Clock RTC Module Board For Arduino
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cablefor Arduino



You do not need a library but I downloaded the library from

This is one of the basic examples, I tested this on a Wemos Mini and Arduino and the results were identical

/* Demonstration of Rtc_Pcf8563 Alarms. 
 * The Pcf8563 has an interrupt output, Pin3.
 * Pull Pin3 HIGH with a resistor, I used a 10kohm to 5v.
 * I used a RBBB with Arduino IDE, the pins are mapped a 
 * bit differently.  Change for your hw.
 * SCK - A5, SDA - A4, INT - D3/INT1
 * After loading and starting the sketch, use the serial monitor
 * to see the clock output.
 * setup:  see Pcf8563 data sheet.
 *         1x 10Kohm pullup on Pin3 INT
 *         No pullups on Pin5 or Pin6 (I2C internals used)
 *         1x 0.1pf on power
 *         1x 32khz chrystal
 * Joe Robertson, jmr
#include <Wire.h>
#include <Rtc_Pcf8563.h>
/* get a real time clock object */
Rtc_Pcf8563 rtc;
/* a flag for the interrupt */
volatile int alarm_flag=0;
/* the interrupt service routine */
void blink()
void setup()
  pinMode(3, INPUT);           // set pin to input
  digitalWrite(3, HIGH);       // turn on pullup resistors
  /* setup int on pin 3 of arduino */
  attachInterrupt(1, blink, FALLING);
  /* clear out all the registers */
  /* set a time to start with.
   * day, weekday, month, century, year */
  rtc.setDate(14, 6, 3, 0, 10);
  /* hr, min, sec */
  rtc.setTime(1, 15, 40);
  /* set an alarm for 20 secs later...
   * alarm pin goes low when match occurs
   * this triggers the interrupt routine
   * min, hr, day, weekday 
   * 99 = no alarm value to be set
  rtc.setAlarm(16, 99, 99, 99);
void loop()
  /* each sec update the display */
  Serial.print("  ");
  Serial.print("  0x");
  Serial.print(rtc.getStatus2(), HEX);
  if (alarm_flag==1){
void clr_alarm()
  attachInterrupt(1, blink, FALLING);



Previous articleESP32 and vibration sensor module
Next articleESP32 and ISL29125 RGB color light sensor