DS1307RTC Clock Module
DS1307 is an I2C real-time clock chip (RTC), it is a low-power, full BCD code clock calendar real-time clock chip with 56 bytes of non-destructive RAM, the address and data are transmitted through a two-wire bidirectional serial bus, the chip can provide seconds, minutes, hours and other information, and the number of days in a month can be automatically adjusted, and there is leap year compensation. The AM/PM flag bit determines whether the clock operates in 24-hour or 12-hour mode, and the chip has a built-in power-sensing circuit with power-down detection and battery switching.
Module Source
Purchase Link:
https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-24706531953.10.2b4a6a4bH7IysA&id=522553351753
Baidu Netdisk Download Link: https://pan.baidu.com/s/1BcLbfV5bCjKdAS4PL3BRnA
Password: 6uq7
Specifications
Operating Voltage:4.5-5.5V
Operating Current:1.5mA
Module Size: 27mm28mm8.4mm
Control Method:IIC
Number of Pins:4 Pin (2.54mm pitch)
Description:with battery, with power failure detection and battery switching function
Hardware Connection
- VCC connects to the 5V of the development board.
- GND connects to the GND of the development board.
- SDA (Serial Data Line) connects to A4 (or SDA port) of the development board.
- SCL (Serial Clock Line) connects to A5 (or SCL port) of the development board.
Usage Method
Install Library
Open the Arduino IDE, go to Tools -> Manage Libraries, search forRTClib
, and then install it. This will allow you to easily work with the DS1307 RTC module.
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 11, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup() {
// 开始串口通讯以便调试
Serial.begin(9600);
// 检查Wire库是否启动而且DS1307是否在运行
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// 检查DS1307是否正在运行
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 设置日期和时间。以下日期/时间是编译这个草稿的时间
// 注意rtc.adjust接收一个DateTime对象,可以按一下方式指定日期:
// DateTime(year, month, day, hour, min, sec)
rtc.adjust(DateTime(__DATE__, __TIME__));
}
}
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.println();
// 延时一些时间,以便阅读
delay(1000);
}
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
58
59
60
61
62