RTC:
An RTC or Real Time Clock is a Timekeeping device,
usually in the form of an Integrated Circuit (IC). An RTC is battery powered
and keeps track of the current time even when there is no power.
Real Time Clock ICs are present in computers, servers
and many embedded systems and in fact they are used wherever it is required to
keep an accurate time.
DS1307 Real Time Clock:
The
DS1307 RTC is a low cost, low power real time clock IC that can maintain full
clock and calendar i.e. hours, minutes, seconds as well as year, month and day.
Some of the well-known features of the popular DS1307 RTC are mentioned below.
·
Complete
Timekeeping functionality i.e. hours, minutes, seconds, year with leap-year,
month, date of the month and day of the week.
·
Low power
consumption: consumes less than 500nA while operated on battery.
·
Automatic
switching to battery supply in case of power failure.
·
24 – hour
or 12- hour clock with AM/PM indicator.
DS1307 RTC Pin Diagram:
Circuit
Diagram of RTC with Arduino:
Code
of RTC with Arduino:
#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
RTC_DS1307 rtc;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (rs, e, d4, d5,
d6, d7)
char daysOfTheWeek[7][12] = {"Sun",
"Mon", "Tue", "Wed", "Thu",
"Fri", "Sat"};
void setup ()
{
Serial.begin(9600);
lcd.begin(16,
2);
if (!
rtc.begin())
{
lcd.print("Couldn't find RTC");
while (1);
}
if (!
rtc.isrunning())
{
lcd.print("RTC is NOT running!");
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));//auto update from
computer time
//rtc.adjust(DateTime(2019, 1, 1, 5, 9, 7));// to set the time manualy
}
void loop ()
{
DateTime now
= rtc.now();
lcd.setCursor(0, 1);
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ,");
lcd.print(now.day());
lcd.print('/');
lcd.print(now.month());
lcd.print('/');
lcd.print(now.year());
}
0 comments:
Post a Comment
if you have any doubt please let me know