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.
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 |
Wiring Diagram #
PIR Motion Sensor | UNO |
---|---|
VCC | 5V |
GND | GND |
SCL | SCL |
SDA | SDA |
Sample Code #
//www.acebott.com
#include // Includes RtcDS1307 library
#include // 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 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
}
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.
Related Resources #
Get One Now #
B2B Business: info@acebott.com