THE COMPONENT REQUIRED : ARDUINO UNO/ ARDUINO DEUMILANOVE
RTC REQUIRED:SparkFun Real Time Clock Module - BOB-12708 - SparkFun Electronics OR ANY WITH 12C INTERFACE
PIN CONNECTION :Real Time Clock DS1307 (RTC) + Arduino
simple code write date/ time in to RTC . It worked for me .i can also able to syn gps time date.
![]()
//Arduino 1.0+ Only
//Arduino 1.0+ Only
#include "Wire.h"
#define DS1307_ADDRESS 0x68
void setup(){
 Wire.begin();
 Serial.begin(9600);
}
void loop(){
 printDate();
 delay(100);
}
byte bcdToDec(byte val)Â {
// Convert binary coded decimal to normal decimal numbers
 return ( (val/16*10) + (val%16) );
}
void printDate(){
 // Reset the register pointer
 Wire.beginTransmission(DS1307_ADDRESS);
 byte zero = 0x00;
 Wire.write(zero);
 Wire.endTransmission();
 Wire.requestFrom(DS1307_ADDRESS, 7);
 int second = bcdToDec(Wire.read());
 int minute = bcdToDec(Wire.read());
 int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
 int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
 int monthDay = bcdToDec(Wire.read());
 int month = bcdToDec(Wire.read());
 int year = bcdToDec(Wire.read());
// this code wil write user define time, date . whenever CPU reset the RTC read data from default. If we syn with gps it read data from GPS.
 /*int second = 12;
 int minute = 30;
 int hour = 21;
 int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
 int monthDay =2;
 int month =11;
 int year = 12;
*/
Â
 Serial.print(month);
 Serial.print("/");
 Serial.print(monthDay);
 Serial.print("/");
 Serial.print(year);
 Serial.print(" ");
 Serial.print(hour);
 Serial.print(":");
 Serial.print(minute);
 Serial.print(":");
 Serial.println(second);
}