Aim:
The Real time clock DS1307 IC basically is stand alone time clock. Well, basically we can use a micrcontroller to keep time, but the value would go off as soon as it is powered off.
The RTC DS1307 is a handy solution to keep time all the way, when it is powered by a coin cell.
Description:
Real Time Clocks, as the name suggests are clock modules. They are available as integrated circuits (ICs) and manages timing like a clock. Some RTC ICs also manages date like a calendar. The main advantage is that they have a system of battery backup which keeps the clock/ca lender running even in case of power failure. A very small current is required for keeping the RTC alive. This in most case is provided by a miniature 3V lithium coin cell. So even if the embedded system with RTC is powered off the RTC module is up and running by the backup cell. This same technique is used in PC timing also. If you have opened your computer case you will notice a small coin cell in the mother board. The DS1307 Serial Real-Time Clock is a low-power; full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially via a 2-wire, bi-directional bus(TWI Communication Protocol). The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator.
In this project, we will learn How to interface a DS1307 Real Time Clock(RTC) with Arduino and LCD Display. Here, we will read time(Minute and Second) from the DS1307 RTC and we will display the minute and second values in a 16X2 alphanumeric LCD. The data communication between DS1307 RTC and Arduino takes place using TWI(Two Wire Interface) communication protocol. But before reading the DS1307 RTC, the DS1307 RTC needs to be initialized with second and minute values. The DS1307 RTC is initialized only once. We will initialize both the minute and second values of the DS1307 RTC with 0(Clock will start with 0 minute and 0 second). You can change the initialization values according to your need by changing the initialization values in the DS1307 write section of the code. After initialization of DS1307 RTC, the Arduino will read the minute and second values from the DS1307 continuously through two wire interface communication and it will display those minute and second values in the 16X2 alphanumeric LCD.
In this project, we will learn How to interface a DS1307 Real Time Clock(RTC) with Arduino and LCD Display. Here, we will read time(Minute and Second) from the DS1307 RTC and we will display the minute and second values in a 16X2 alphanumeric LCD. The data communication between DS1307 RTC and Arduino takes place using TWI(Two Wire Interface) communication protocol. But before reading the DS1307 RTC, the DS1307 RTC needs to be initialized with second and minute values. The DS1307 RTC is initialized only once. We will initialize both the minute and second values of the DS1307 RTC with 0(Clock will start with 0 minute and 0 second). You can change the initialization values according to your need by changing the initialization values in the DS1307 write section of the code. After initialization of DS1307 RTC, the Arduino will read the minute and second values from the DS1307 continuously through two wire interface communication and it will display those minute and second values in the 16X2 alphanumeric LCD.
Block Diagram
Schematic
Code
// ****************************************************** // Project: RTC interfacinig using Arduino // Author: Hack Projects India // Module description: Operate DS1307 RTC IC // ****************************************************** #include <Wire.h> #include <RealTimeClockDS1307.h> #include <LiquidCrystal.h> // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 8, en = 9, d4 = 2, d5 = 3, d6 = 4, d7 = 5; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); #define Display_Clock_Every_N_Seconds 10 #define Display_ShortHelp_Every_N_Seconds 60 String tz; int hours = 0; int minutes = 0; int seconds = 0; int dates = 0; int months = 0; int years = 0; int ap = 0; void setup() { Serial.begin(9600); lcd.begin(16,2); pinMode(A3, OUTPUT); digitalWrite(A3, HIGH); pinMode(A2, OUTPUT); digitalWrite(A2, LOW); } void loop() { RTC.readClock(); if(ap == 1) { tz = "PM"; } else { tz ="AM"; } lcd.home(); hours = RTC.getHours(); minutes = RTC.getMinutes(); seconds = RTC.getSeconds(); ap = RTC.isPM(); dates = RTC.getDate(); months = RTC.getMonth(); years = RTC.getYear(); lcd.print(hours); lcd.print(":"); lcd.print(minutes); lcd.print(":"); lcd.print(seconds); lcd.print(" "); lcd.print(tz); lcd.setCursor(0, 1); lcd.print(dates); lcd.print(":"); lcd.print(months); lcd.print(":"); lcd.print(years); delay(250); lcd.clear(); lcd.home(); lcd.print(hours); lcd.print(" "); lcd.print(minutes); lcd.print(" "); lcd.print(seconds); lcd.print(" "); lcd.print(tz); lcd.setCursor(0, 1); lcd.print(dates); lcd.print(" "); lcd.print(months); lcd.print(" "); lcd.print(years); delay(250); lcd.clear(); }
No comments:
Post a Comment