Overview
The DS1307 is a real-time clock (RTC) module. Its function is to keep time. This is especially
useful for Arduino projects because the Arduino is only able to keep track of time since it was
powered on. Once its off, it has no way of keeping time. The DS1307 RTC is powered by a small
coin battery so it will continue to keep time even when the Arduino is off or reprogrammed.
Sample Program
Open the Arduino IDE and go to Edit > Examples > RTClib-master > ds1307 to open a sketch
(code) that will set the time of the RTC module. You should see this sketch:
This code will set the RTC to when the sketch was compiled, or to the specific time you input. But
first you must uncomment the line of code (line 21 or line 24, respectively) that does this. Simply
delete the // before the line of code. Run the code by clicking the right-pointing arrow (upload)
on the menu bar, then click the magnifying glass icon to pull up the serial monitor and see the
output of the code. Make sure the correct baud rate (57600) is selected on the drop-down menu on
the lower right of the serial monitor.
The output you should see is the real-time based on the time that was set, the time since midnight
1/1/1970, and the time to some specified future date (a week in advance, by default, but this can
be modified). This loops every 3 seconds but again this is something that can be modified by
changing the value (in milliseconds) inside delay(). Below is the part of the sketch where you can
change the future time and the loop delay.