This tutorial we will going to wire the DS1307 Module with on Chip I2C. which is output the real time clock signal through standard I2C interface. The DS1307 Serial Real Time Clock is a low power, full BCD (binary-coded decimal) clock/calendar and it has 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, If you want to know more about i2c check this link. “How I2C Serial Bus Works”
The clock and calendar provides seconds, minutes, hours, days, date, month, and year information. The end of the month date is automatically adjusted for months with fewer that 31 days including corrections for leap year.
The clock operates in 24 hours or 12 hours format along with AM and PM indicator. The DS1307 has a builtin power sense circuit that detects power failure and automatically switch to the backup power supply. Timekeeping operation continues while the part operates from the power backup supply.
Wiring the I2C DS1307 Real Time Clock
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <Wire.h> // Include the Wire Library to use the I2C Serial Bus #include <myRTClib.h> // Include myRTC Library myRTC_DS1307 mymyRTC; void setup () { Serial.begin(9600); //Set Serial boud rate 9600 Wire.begin(); myRTC.begin(); if (! myRTC.isrunning()) { Serial.println("Real Time Clock is Not Running"); myRTC.adjust(DateTime(__DATE__, __TIME__)); } } void loop () { DateTime now = myRTC.now(); // Now Date & Time Serial.print(now.year(), DEC); // Set as Year Serial.print('/'); Serial.print(now.month(), DEC); // Set as Month Serial.print('/'); Serial.print(now.day(), DEC); // Set as Days Serial.print(' '); Serial.print(now.hour(), DEC); // Set as Hour Serial.print(':'); Serial.print(now.minute(), DEC); // Set as Minute Serial.print(':'); Serial.print(now.second(), DEC); // Set as Second Serial.println(); delay(1000); // Delay for 1 sencond } |
The Serial Communication View
When you going to place the coin battery it will display the right date & time.
Download The Code Library Here | Zip
Download The DS1307 Datasheet Here | PDF