Real Time Clock DS1307 interfacing with Arduino Uno

I am currently working on an electronics project of building my own Digital wall clock. For that I tried making a RTC module with DS1307 IC.

I followed the following instruction from this website.

But when I tried to read and write the time to the IC using the serial monitor on Arduino software I got the following result.

My inputs were as follows:

first i/p : T000021240114

second i/p: R

Can someone help me find my mistake.

From the code:

second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
dayOfWeek = (byte) (Serial.read() - 48);


All have two characters except for dayOfWeek

So for right now (2014-01-25 13:58:00) it would be 14 characters (including 'T')

T0058136250114


You only have 13 characters in your command.

Also you need 4K7 - 10K pullups on SDA and SCL. Note that "Command: 13" in the log is just the carriage return character (enter). Since you had too few characters in the command, it was interpreted as part of the command.

• can you explain more about the resistors. there is none specified in the schematics. also i changed the command, but still getting garbage values. The new log can you look into it again. thanks. – BharathYes Jan 25 '14 at 8:04
• @BharathYes The pullup resistors are required for I2C. The page you have linked used an RTC board that already has these two resistors included. You have used a bare chip so you need to add the resistors. – alexan_e Jan 25 '14 at 9:21
• thanks for the help. turns out the battery wasn't connected properly. but i have a new bug. the time doesn't change for some time. the seconds is updated by one only once every two minutes. do you think there might be something wrong with the crystal ???? – BharathYes Jan 25 '14 at 12:33
• @BharathYes What crystal are you using? The data sheet says there is an app note: "Application Note 58: Crystal Considerations with Dallas Real-Time Clocks.". Does it increment regularly every 2 mins or randomly? – geometrikal Jan 25 '14 at 13:29
• i bought the crystal at a local electrical store. I asked for a 32.768 kHz crystal, but nothing on it says so. it only has a name "KOSOL" and am assuming it is the manufacturer's name. Also the time seems to increment a little randomly. can you find anything wrong ? – BharathYes Jan 25 '14 at 13:43