Real Time Clock
Real Time Clock
Real Time Clock
with Arduino
Bilal Malik 2 Years Ago 5 Comments
real time clock DS1307 interfacing with Arduino, In this article you will learn
how to interface real time clock DS1307 with Arduino. What is real time? why
real time clock is used? what is dedicated integrated circuit for real time
clock? how to make digital clock using Arduino and integrated circuit
DS1307? What are application of real time clock DS1307? Hardware
connections of liquid crystal display 16 X 2 LCD and real time clock DS1303
with Arduino. How to use library of real time clock to display time and date
on LCD? You will get answers of all your questions in this article.
Before reading this article you should have a basic knowledge about Arduino
and its use. You should know how to interface LCD with Arduino and how to
use input/ output ports of Arduino. If you dont know how to do these things. I
recommend you to go throgh following articles to get better understanding of
this article. Because I have already posted articles on such things. For more
information check following articles.
Programming:
The code given below is write to display date and time on LCD.
#include <Wire.h>
#include RTClib.h
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
lcd.begin(20, 4);
pinMode(8,OUTPUT);
if (! RTC.isrunning()) {
Serial.println(RTC is NOT running!);
// following line sets the RTC to the date & time this sketch was
compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
DateTime now = RTC.now();
lcd.setCursor(0, 0);
lcd.print(now.day(), DEC);
lcd.print(/);
lcd.print(now.month(), DEC);
lcd.print(/);
lcd.print(now.year(), DEC);
lcd.print( );
lcd.setCursor(0, 1);
if (now.hour()<10)
lcd.print(0);
lcd.print(now.hour(), DEC);
lcd.print(:);
if (now.minute()<10)
lcd.print(0);
lcd.print(now.minute(), DEC);
lcd.print(:);
if (now.second()<10)
lcd.print(0);
lcd.print(now.second(), DEC);
delay(1000);
}
The result of above code is given below:
circuit diagram of DIgital clock using real time clock and Arduino result
In above code #include RTClib.h is used to include library of real time
clock. If you dont have already library installed in your Arduino IDE compiler.
you can add it very easily. Download library from given below link. After
downloading code, abstract the code and paste the file into libraries folder of
Arduino UNO folder.