Real Time Clock (RTC) PCF8563

Real Time Clock (RTC) PCF8563 © CC BY-SA

This lesson aims to show how to use the famous PCF8563 (a real time clock RTC) with Arduino through the library written by Joe Robertson.

  • 7,720 views
  • 1 comment
  • 6 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
PCF8563
×1
Crystal 32kHz
×1
10kOhm Resistor
×1
100nF Capacitor
×1
jumpers
×1
12002 04
Breadboard (generic)
×1

About this project

How does it work?

The communication between Arduino and the PCF8563 use the TWI (I2C) so we have to use A4 and A5 pins.

A first schematic

A first schematic could be the following. But there is a problem: if the Arduino is disconnected from the USB, the clock "forgets" the time, so this clock is not very useful!

A second schematic

To skip this problem we can use a backup battery, as used in this second schematic.

Set Date & Time

To set date and time, we have to use this code and program the Arduino. After, we can check if the clock works through the serial monitor.

/* Demonstration of Rtc_Pcf8563 Set Time. 
 * Set the clock to a time then loop over reading time and 
 * output the time and date to the serial console.
 *
 * 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
 * orbitalair@bellsouth.net
 */ 
#include 
#include 
//init the real time clock
Rtc_Pcf8563 rtc;
void setup()
{
  //clear out the registers
  rtc.initClock();
  //set a time to start with.
  //day, weekday, month, century(1=1900, 0=2000), year(0-99)
  rtc.setDate(14, 6, 3, 1, 10);
  //hr, min, sec
  rtc.setTime(1, 15, 0);
  Serial.begin(9600);
}
void loop()
{
  //both format functions call the internal getTime() so that the 
  //formatted strings are at the current time/date.
  Serial.print(rtc.formatTime());
  Serial.print("\r\n");
  Serial.print(rtc.formatDate());
  Serial.print("\r\n");
  delay(1000);
} 

Code

Code snippet #1Arduino
/* Demonstration of Rtc_Pcf8563 Set Time. 
 * Set the clock to a time then loop over reading time and 
 * output the time and date to the serial console.
 *
 * 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
 * orbitalair@bellsouth.net
 */ 
#include 
#include 

//init the real time clock
Rtc_Pcf8563 rtc;

void setup()
{
  //clear out the registers
  rtc.initClock();
  //set a time to start with.
  //day, weekday, month, century(1=1900, 0=2000), year(0-99)
  rtc.setDate(14, 6, 3, 1, 10);
  //hr, min, sec
  rtc.setTime(1, 15, 0);
  Serial.begin(9600);
}

void loop()
{
  //both format functions call the internal getTime() so that the 
  //formatted strings are at the current time/date.
  Serial.print(rtc.formatTime());
  Serial.print("\r\n");
  Serial.print(rtc.formatDate());
  Serial.print("\r\n");
  delay(1000);
}

Comments

Similar projects you might like

Arduino OLED Temperature Display with Real Time Clock

Project tutorial by Keval Doshi

  • 7,459 views
  • 7 comments
  • 31 respects

LED Ring Real Time Clock

Project showcase by 3 developers

  • 1,346 views
  • 0 comments
  • 1 respect

LCD with DS3231 Real Time Clock Module

Project showcase by Tan See Youu

  • 39,452 views
  • 0 comments
  • 30 respects

Digital And Binary Clock With Two LED Matrix And RTC

Project tutorial by LAGSILVA

  • 6,117 views
  • 10 comments
  • 27 respects

Clock without using RTC in Arduino with Temperature and humi

Project tutorial by ahmadordi

  • 5,611 views
  • 9 comments
  • 23 respects
Add projectSign up / Login