Anda di halaman 1dari 3

DS1307 Real-Time Clock (RTC) Module - Arduino Tutorial

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.

Wiring and Connection

Connect GRD pin to GRD.


Connect 5V pin to 5V.
Connect SDA pin to A4 (SDA pin on Arduino UNO).
Connect SCL pin to A5 (SCL pin on Arduino UNO).
Supporting Software
1. Libraries
a. For this tutorial, you will need to the download a library from Github.
Go to this link.
Click the green Clone or download button.
Save the zip file.
Locate your Arduino folder and move the zip file to the Libraries folder in your
Arduino folder.
Unzip the file.
2. Tutorials
a. Tutorials to set up this RTC module can be found in the following links:
Adafruit
Sparkfun
Instructables
3. Example programs
a. Example programs to set and read time can be found in the following links:
Adafruit
Sparkfun

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.

Your serial monitor window should show:

Anda mungkin juga menyukai