Pages

Wednesday, 22 January 2014

How to use pcf8563p real time clock IC with Arduino


In this blog you will learn,how to use a real time clock ic with Arduino


This is the basic Description of pcf8563 is based on the Nxp datasheet.
"The PCF8563 is a CMOS1 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 I2C-bus. Maximum bus speed is 400 kbit/s. The register address is incremented automatically after each written or read data byte."


Pin Diagram-





The time and date can be set using the Arduino . An optional battery can be used to back up the time and date settings in the real time clock chip so that the time and date are not lost if the Arduino power is unplugged.

Components needed for prototyping -

1 -32.768 khz crystal.
2- 2.2 kohm resistor.
1-pcf8563 real time clock ic.
1-100 nf capacitor

Follow these instruction to connect the real time ic with arduino with out backup power supply.

  1. Connect crystal between the 1st and 2nd pin of the pcf8563p ic.
  2. Connect the 4th pin of the pcf8563 ic to the arduino ground pin.
  3. Connect the analog pin A5 of arduino with the 6th pin of the pcf8563.
  4. Connect the analog pin A4 of arduino with the 5th pin of the pcf8563.
  5. Connect the 8th pin of the pcf8563 with the vcc of  the arduino.
  6. Now connect the 100n capacitor between the 8th pin of pcf8563 and ground pin of arduino.
  7. Connect the 2.2k resistor between the vcc of arduino and 5th pin of pcf8563.
  8. Connect the 2.2k resistor between the vcc of arduino and 6th pin of pcf8563.  


The resulted circuit shown as the figure below-



You can connect a backup power supply to it just by adding two diodes and a 3 volt power source as shown in the figure below.




Now download RTCpcf8563 library which was written by "Joe Robertson" and say thanks to him.

unzip  and save it to your arduino folder, Now open  an example called led_clock  to your Arduino Ide.

This code was orignally written to show the time and date on a lcd screen and many of us don't have lcd screen so i changed this code to show time and date on a serial monitor.

Copy and paste the code given below to your Arduino IDE

#include <Wire.h>
#include <Rtc_Pcf8563.h>

//init the real time clock
Rtc_Pcf8563 rtc;


void setup()
{
  Serial.begin(9600);
  rtc.initClock();
  //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);
}

void loop()
{

 Serial.println(rtc.formatTime());
  Serial.println(rtc.formatDate());
Serial.println(rtc.getHour()); // this will print the hour alone
Serial.println(rtc.getMinute());// this will print the minute alone
  Serial.println(rtc.getDay());// this will print the day alone and so on...
  delay(1000);
    
}

// end of the code

Hey guys, thanks for reading my blog.

I've made a chrome extension mYoutube for YouTube™. It is designed for a more comfortable watching experience.

✔ Instant control over volume by scrolling mouse wheel on the video.

✔ You can permanently disable video Annotations.

✔ Read Comments, see Related-Videos and Info without leaving video from sight. 

✔ Auto turn off lights, when mouse stays more than 2 seconds on the video player. 

Please take a look at it - mYoutube
Like mYoutube on Facebook 






8 comments:

  1. Emplotime is an online project management application that bundles time tracking, task management and invoicing. This means that you can keep track of the entire lifetime of a project (from creation until getting paid) without having to use and pay for several apps.

    ReplyDelete
  2. Hello, is it a 32,xx kHz Crystal Oscillator or 32 MHz one? thank you

    ReplyDelete
  3. yes, it's the same

    ReplyDelete
  4. hello.. can i make a propeller clock without the real timer IC? isn't that Atmega's has built in RTCs?

    ReplyDelete
  5. hello.. can i make a propeller clock without the real timer IC? isn't that Atmega's has built in RTCs?

    ReplyDelete
  6. hello.. can i make a propeller clock without the real timer IC? isn't that Atmega's has built in RTCs?

    ReplyDelete
  7. is it necessary to put 3 v battery ??

    ReplyDelete
  8. hello..
    Is this program really work?
    When I run this program, it does not work actually.
    It showed the wrong numbers.

    ReplyDelete