QB047 DS1307 Clock Module

1.Product Introduction

../../_images/DS1307-1.png

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
../../_images/DS1307-5.jpg

3.Wiring Diagram

../../_images/DS1307-2.png
PIR Motion Sensor UNO
VCC 5V
GND GND
SCL SCL
SDA SDA

4.Sample Code

 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
//www.acebott.com
#include <RtcDS1307.h> // Includes RtcDS1307 library
#include <Wire.h>    // Includes Wire library for I2C communication
volatile int year;
volatile int month;
volatile int day;
volatile int hour;
volatile int minute;
volatile int second;
RtcDS1307<TwoWire> Rtc(Wire);
 // Create RtcDS1307 object for I2C communication using Wire library
void setup(){
  year = 0;
  month = 0;
  day = 0;
  hour = 0;
  minute = 0;
  second = 0;
  Rtc.Begin(); // Initialize RtcDS1307
  Rtc.SetIsRunning(true); // Start the DS1307 real-time clock
  Rtc.SetDateTime(RtcDateTime(__DATE__, __TIME__)); // Set the date and time of the DS1307 to the date and time at compile time
  Serial.begin(9600); // Initialize serial communications
}

void loop(){
  // Get the current date and time from the DS1307 real-time clock
  year = Rtc.GetDateTime().Year();
  month = Rtc.GetDateTime().Month();
  day = Rtc.GetDateTime().Day();
  hour = Rtc.GetDateTime().Hour();
  minute = Rtc.GetDateTime().Minute();
  second = Rtc.GetDateTime().Second();
  // Print date and time to serial port
  Serial.println(String(String(year) + String("Year")) + String(String(String(month) + String("Month")) + String(String(day) + String("Day"))));
  Serial.println(String(String(hour) + String(":")) + String(String(String(minute) + String(":")) + String(second)));
  delay(1000); // 1 second delay to control output frequency

}

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.

../../_images/DS1307-3.png
../../_images/DS1307-4.png

6.Related Resources

7.Get One Now

B2B Business: info@acebott.com

Individual buyer: shop on aliexpress