1.Product Introduction
The DS1307 is a common real-time clock (RTC) module that integrates clock and calendar functions and provides accurate time and date information. It is often used with a controller to get an accurate timestamp or perform timed tasks when there is no network connection.
The DS1307 module uses the I2C bus for communication and can be connected to the I2C bus of the microcontroller. It contains a 32kHz real-time clock crystal to provide a high precision time reference. The module also has a battery backup power interface to keep time data stable when the main power is disconnected. The DS1307 module stores the year, month, date, hour, minute and second information, which can be set and obtained by reading and writing registers.
Application reference: electronic clocks, timers, timing switches, temperature monitoring and other scenarios that need to achieve accurate time.
2.Parameter Specification
Parameter | Value//Description |
---|---|
Operating voltage | 5V |
Operating temperature | -40°C~+85°C |
Storage capacity | 56Byte |
Clock frequency | 32.768KHz |
Communication mode | IIC |
Size | 4.72cm*2.38cm |
3.Wiring Diagram
PIR Motion Sensor | UNO |
---|---|
VCC | 5V |
GND | GND |
SCL | SCL |
SDA | SDA |
4.Sample Code
1//www.acebott.com
2#include <RtcDS1307.h> // Includes RtcDS1307 library
3#include <Wire.h> // Includes Wire library for I2C communication
4volatile int year;
5volatile int month;
6volatile int day;
7volatile int hour;
8volatile int minute;
9volatile int second;
10RtcDS1307<TwoWire> Rtc(Wire);
11 // Create RtcDS1307 object for I2C communication using Wire library
12void setup(){
13 year = 0;
14 month = 0;
15 day = 0;
16 hour = 0;
17 minute = 0;
18 second = 0;
19 Rtc.Begin(); // Initialize RtcDS1307
20 Rtc.SetIsRunning(true); // Start the DS1307 real-time clock
21 Rtc.SetDateTime(RtcDateTime(__DATE__, __TIME__)); // Set the date and time of the DS1307 to the date and time at compile time
22 Serial.begin(9600); // Initialize serial communications
23}
24
25void loop(){
26 // Get the current date and time from the DS1307 real-time clock
27 year = Rtc.GetDateTime().Year();
28 month = Rtc.GetDateTime().Month();
29 day = Rtc.GetDateTime().Day();
30 hour = Rtc.GetDateTime().Hour();
31 minute = Rtc.GetDateTime().Minute();
32 second = Rtc.GetDateTime().Second();
33 // Print date and time to serial port
34 Serial.println(String(String(year) + String("Year")) + String(String(String(month) + String("Month")) + String(String(day) + String("Day"))));
35 Serial.println(String(String(hour) + String(":")) + String(String(String(minute) + String(":")) + String(second)));
36 delay(1000); // 1 second delay to control output frequency
37
38}
5.Test Result
After uploading the code to the controller board, open the serial port monitor of the Arduino IDE and set the baud rate to 9600.
The serial port will print out the current time.
6.Related Resources
7.Get One Now
B2B Business: info@acebott.com