DS1307

The DS1307 is a real time clock. Looking to buy or find the datasheet. Look here.

  • Two wire I2C interface with adress at 0x68
  • Hour : Minutes : Seconds AM/PM
  • Day Month, Date – Year
  • Leap year compensation
  • Accurate calendar up to year 2100
  • Battery backup included
  • 1Hz output pin
  • 56 Bytes of Non-volatile memory available to user
  • DS1307 dimensions: 0.75×0.75″ (20x20mm)
shop button

DS1307  board

I started off using a small DS1307 breakout board from jeelabs. The schematic for this is shown below.
You simply wire up SDA SCK and the two power connections. After testing this with a mini breadboard i decided to see if it would run directly placed on the arduino.
Only two small changes are needed to the PCB which are illustrated on the right. You link a wire from P to A as shown. Then you use a stanley knife to break the connection between the two A pins as shown.
Getting the power directly from the arduino digital pins is using the same idea as i used on the DS18B20. Again there is the need for a small software adaptation to make it work. Basically putting the correct digital IO to Ground and +5V. Later on i also added two 2.2k pull up resistors to the SCK and SDA pins. They are not really needed.

DS1307schematicDS1307shield

I downloaded the DS1307 library for this is at adafruit.  https://github.com/adafruit/RTClib but actually it is from Jeelabs.
As explained you need to make some small mods to set the power supply. This modded library for the DS1307 including the arduino sketch can be downloaded here.

[spoiler]
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

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

RTC_DS1307 RTC;

void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
RTC.setpowerpins();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
}
RTC.adjust(DateTime("Dec 26 1957","12:34:56"));
}

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 midnight 1/1/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);
}
[/spoiler]

The output from the program you can see below.

DS1307output
I designed a small PCB which enables you to connect the device directly to an arduino. The design is shown below.
I have made several boards and they are available in the shop.

shop button

DS1307newschematicDS1307newbrd

DS1307 links.

http://www.glacialwanderer.com/hobbyrobotics/?p=12

Leave a Reply