REAL TIME CLOCK MODULE

Description

  • Real-time clock counts seconds, minutes, hours, day of the month, month, day of the week and year, with leap year
  • Compensation valid up to the year 2100
  • Simple serial port interfaces to most microcontrollers, I2C serial interface
  • Low power operation extends battery back-up run time
  • Automatic power-fail detection and switch circuitry

Battery powered clock/calendar that keeps track of time even when your Arduino-compatible board is powered off. Automatically detects power failure and switches to battery (CR1225). On battery backup it will run for years. Has a simple to use I2C serial interface with only 4 cables including power. Useful for data logging or for time sensitive projects, e.g. turning on coffee-machines at 5 a.m., watering plants twice a week at 5 p.m., etc.

Supply voltage 4.5 to +5.5 VDC 1.5 mA
Battery voltage 2 to +3.5 VDC 50 nA
Leap year compensation Valid up to the year 2100
Battery-backed memory 56-byte, battery-backed, general-purpose
RAM with unlimited writes
Maximum voltage range on any pin relative to ground -0.5V to +7.0V
Operating temperature 0°C to +70°C
Battery backup time A lithium battery with 48 mAh or greater will back up the
DS1307 for more than 10 years in the absence of power at +25 °C.

Easy to connect, with only four cables. You can pin the module on the breadboard and use the male to male jumper cables, or use the male to female jumper cables to connect the module directly to the Arduino-compatible board.

To supply voltage to the board, connect the +5v pin to the 5v power pin and the GND pin to the GND pin. If you want to use an external power supply, be sure to connect the grounds together with the serial transmitting/receiving device. Connect SCL to A5 and SDA to A4 on your Arduino-compatible board.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Reviewed by Dr. Mangus  from MangoLabs
   -- RTC Led tst --
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
*/
 
#include <Wire.h>
#include "RTClib.h"
 
RTC_DS1307 rtc;
 
char daysOfTheWeek[7][12] = {"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};
 
void setup () {
  while (!Serial); // for Leonardo/Micro/Zero
 
  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
 
  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Comment out after setting the RTC with //
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}
 
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(daysOfTheWeek[now.dayOfTheWeek()]);
    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");
     
       delay(3000);
}
  1. In this example we are connecting:
    Arduino      RTC
    A4      —    SDA
    A5      —    SCL
    GND  —   GND
    5V     —   VCC
  2. Download and install the Arduino environment from here or use the web editor.
  3. Download the Arduino libraries here.
  4. Unzip and paste the folder in the Arduino libraries folder. It’s in the same location as your default sketches. To find the sketchbook location, go to File / Preferences.
  5. Download this sketch and open or open the Arduino environment and copy the code into a blank sketch.
  6. Connect your board to your computer with the included USB cable.
  7. Select your board in Tools / Board / Arduino Uno.
  8. Select your port in Tools / Port / COM# (Arduino Uno). This may be slightly different depending on your operating system.
  9. Upload by pressing the arrow in the circle to the upper left.
  10. To open the serial monitor, press the magnifying glass icon on the upper right.
  11. Set the baud rate to 57600 on the lower right.
  12. The clock is now set to the time you compiled and uploaded to the sketch and should be running. You will see the time and some time calculations.