Stufin
Home Quick Cart Profile

DS1307 Real Time Clock Module

Buy Now on Stufin

Supply Voltage

4.5V to 5.5V

Backup Battery Voltage

2.0V to 3.5V

Clock Frequency

32.768 kHz (standard), programmable from 1Hz to 4096Hz

Serial Interface

I2C (up to 400kHz) or SPI (up to 4MHz)

Memory

56 bytes of non-volatile memory for storing time, date, and other calendar information

Applications

The DS1307 Real Time Clock Module is suitable for a wide range of IoT applications, including

Wearable Devices

Fitness trackers, smartwatches, and other wearables that require accurate timekeeping and low power consumption.

Industrial Automation

Machine monitoring, process control, and automation systems that require precise time stamps and alarm functions.

Smart Home Devices

Home automation systems, thermostats, and security systems that benefit from accurate timekeeping and calendar features.

Medical Devices

Medical equipment, such as patient monitors and infusion pumps, that require reliable timekeeping and alarm functions.

Conclusion

The DS1307 Real Time Clock Module is a versatile, low-power, and highly accurate time-keeping component suitable for a wide range of IoT applications. Its compact form factor, low power consumption, and backup battery feature make it an ideal choice for battery-powered devices and systems that require precise timekeeping and calendar functionality.

Pin Configuration

  • DS1307 Real Time Clock Module Pinout Explanation
  • The DS1307 Real Time Clock (RTC) module is a widely used component in IoT projects, providing accurate timekeeping and calendar functions. The module consists of 8 pins, which are explained below:
  • 1. VCC (Power Supply Pin)
  • Function: Provides power to the DS1307 chip
  • Pin Type: Input
  • Voltage Range: 4V to 5.5V (Typical Operating Voltage: 5V)
  • Connection: Connect to a stable 5V power supply or a 3.3V power supply with a suitable voltage regulator
  • 2. GND (Ground Pin)
  • Function: Provides a reference ground for the DS1307 chip
  • Pin Type: Input
  • Connection: Connect to the ground of the power supply or the circuit's ground
  • 3. SCL (Serial Clock Pin)
  • Function: Receives the clock signal from the microcontroller or other devices
  • Pin Type: Input
  • Connection: Connect to the SCL pin of the microcontroller or other I2C devices
  • 4. SDA (Serial Data Pin)
  • Function: Transfers data between the DS1307 and the microcontroller or other devices
  • Pin Type: Bidirectional
  • Connection: Connect to the SDA pin of the microcontroller or other I2C devices
  • 5. SQW (Square Wave Output Pin)
  • Function: Outputs a square wave signal, which can be used as a clock signal for other devices
  • Pin Type: Output
  • Connection: Connect to a digital pin of the microcontroller or other devices that require a clock signal
  • 6. RST (Reset Pin)
  • Function: Resets the DS1307 chip when pulled low
  • Pin Type: Input
  • Connection: Typically connected to a digital pin of the microcontroller or a pull-up resistor
  • 7. BAT (Battery Input Pin)
  • Function: Connects to a 3V lithium battery or a supercapacitor for backup power
  • Pin Type: Input
  • Connection: Connect to a 3V lithium battery or a supercapacitor for backup power
  • 8. NC (No Connection Pin)
  • Function: Not connected internally
  • Pin Type: NC (No Connection)
  • Connection: Leave unconnected
  • Connection Structure:
  • When connecting the DS1307 RTC module to a microcontroller or other devices, follow these steps:
  • 1. Connect VCC to a stable 5V power supply or a 3.3V power supply with a suitable voltage regulator.
  • 2. Connect GND to the ground of the power supply or the circuit's ground.
  • 3. Connect SCL to the SCL pin of the microcontroller or other I2C devices.
  • 4. Connect SDA to the SDA pin of the microcontroller or other I2C devices.
  • 5. Connect SQW to a digital pin of the microcontroller or other devices that require a clock signal (optional).
  • 6. Connect RST to a digital pin of the microcontroller or a pull-up resistor (optional).
  • 7. Connect BAT to a 3V lithium battery or a supercapacitor for backup power (optional).
  • 8. Leave the NC pin unconnected.
  • Remember to consult the datasheet and relevant documentation for specific connection requirements and precautions when using the DS1307 RTC module in your IoT project.

Code Examples

DS1307 Real Time Clock Module Documentation
Overview
The DS1307 Real Time Clock (RTC) module is a widely used component in IoT projects that require accurate timekeeping. It's a low-power, binary-coded decimal (BCD) clock/calendar chip with a built-in 56-byte RAM for data storage. This module provides a reliable and efficient way to keep track of time, date, and other parameters in various applications.
Pinout and Connection
The DS1307 RTC module typically has the following pinout:
VCC: Power supply (1.8V to 5V)
 GND: Ground
 SDA: I2C data line
 SCL: I2C clock line
 RST: Reset pin (active low)
Connect the module to a microcontroller or other I2C-compatible devices using the SDA and SCL pins. Make sure to connect the RST pin to a suitable pull-up resistor and a reset button (if required).
Code Examples
### Example 1: Basic Timekeeping using Arduino
In this example, we'll use an Arduino Uno board to interact with the DS1307 RTC module.
```c
#include <Wire.h>
#include <DS1307.h>
DS1307 RTC;
void setup() {
  Wire.begin();
  RTC.begin();
// Set the time (optional)
  RTC.set(DS1307seconds, 0);
  RTC.set(DS1307minutes, 30);
  RTC.set(DS1307hours, 12);
  RTC.set(DS1307day, 1);
  RTC.set(DS1307month, 1);
  RTC.set(DS1307year, 2023);
}
void loop() {
  // Get the current time
  int seconds = RTC.get(DS1307seconds);
  int minutes = RTC.get(DS1307minutes);
  int hours = RTC.get(DS1307hours);
  int day = RTC.get(DS1307day);
  int month = RTC.get(DS1307month);
  int year = RTC.get(DS1307year);
Serial.print("Time: ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.print(":");
  Serial.println(seconds);
Serial.print("Date: ");
  Serial.print(day);
  Serial.print("/");
  Serial.print(month);
  Serial.print("/");
  Serial.println(year);
delay(1000);
}
```
### Example 2: Time-Based Automation using Raspberry Pi (Python)
In this example, we'll use a Raspberry Pi to read the time from the DS1307 RTC module and control an LED based on a schedule.
```python
import I2C
import time
import RPi.GPIO as GPIO
# Set up the I2C bus
i2c = I2C.I2C(bus=1)
# Set up the DS1307 RTC module
rtc = i2c.add_slave(0x68, 0)
# Set up the GPIO pin for the LED
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
while True:
    # Read the current time
    seconds = rtc.read(0x00)
    minutes = rtc.read(0x01)
    hours = rtc.read(0x02)
# Check if it's 8:00 AM
    if hours == 8 and minutes == 0:
        GPIO.output(17, GPIO.HIGH)
    else:
        GPIO.output(17, GPIO.LOW)
# Wait for 1 second
    time.sleep(1)
```
### Example 3: Power-Fail Detection and Backup using ESP32 (C++)
In this example, we'll use an ESP32 board to detect power failures and maintain the RTC module's timekeeping functionality using an external battery.
```c
#include <WiFi.h>
#include <DS1307.h>
DS1307 rtc;
void setup() {
  Serial.begin(115200);
// Initialize the RTC module
  rtc.begin();
// Set up the external battery for power-fail detection
  pinMode(32, INPUT); // VBAT pin
// Initialize the ESP32's internal RTC
  rtc.set(0, 0, 0, 1, 1, 2023);
}
void loop() {
  // Check for power-fail detection
  if (digitalRead(32) == LOW) {
    Serial.println("Power failure detected!");
    // Use the external battery to maintain timekeeping
    rtc.setBattery(true);
  } else {
    Serial.println("Power OK!");
    // Use the internal power source
    rtc.setBattery(false);
  }
// Get the current time
  int seconds = rtc.get(DS1307seconds);
  int minutes = rtc.get(DS1307minutes);
  int hours = rtc.get(DS1307hours);
Serial.print("Time: ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.print(":");
  Serial.println(seconds);
delay(1000);
}
```
These examples demonstrate the basic usage of the DS1307 Real Time Clock module in various contexts. You can modify and expand upon these examples to suit your specific IoT project requirements.