# real time clck -RTC DS 1307- to Arduino

I am trying to connect the ds1307 to Arduino to get the the time on the LCD and I used this circuit in my project and I tried the example code in the library but it didn't work. What could the problem be?

# the code:

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();

if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
}

}

void loop () {
DateTime now = RTC.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since 1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(3000);
}


============================

-
 the first one #include – alone Sep 18 '12 at 20:17 Are you seeing anything at the serial port on the computer? – justing Sep 18 '12 at 20:29

It won't work if there are no pullups on the lines, because I2C uses an open drain bus.

Add a 2.2kΩ resistor (can be anything between this and 10kΩ, a lower value is better for long lines and higher clock speed) from SCL to +5V and also another one from SDA to +5V (so one between DS1307 pins 5 and 8, another one between pins 6 and 8) .

The resistors (marked Rp) are shown below:

If you need the square wave out, you will also need a pullup on this too, details are in the datasheet.

-
 oh thanks.... i wiil try this and i hope it work – alone Sep 19 '12 at 6:09