Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use DS1307 RTC: Examples, Pinouts, and Specs

Image of DS1307 RTC
Cirkit Designer LogoDesign with DS1307 RTC in Cirkit Designer

Introduction

The DS1307 is a real-time clock (RTC) chip designed to keep track of the current time and date, including seconds, minutes, hours, day, date, month, and year. It communicates with microcontrollers using the I2C (Inter-Integrated Circuit) protocol, making it easy to integrate into a wide range of electronic projects. One of its key features is the ability to maintain timekeeping even during power outages, thanks to its built-in battery backup functionality.

Explore Projects Built with DS1307 RTC

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Arduino UNO with DS1307 RTC Controlled LED Lighting System
Image of li8: A project utilizing DS1307 RTC in a practical application
This circuit features an Arduino UNO connected to a DS1307 Real Time Clock (RTC) module for timekeeping and a red LED with a series resistor for indication purposes. The Arduino communicates with the RTC via I2C (using A4 and A5 pins for SDA and SCL, respectively), and controls the LED connected to digital pin D8 through a 330-ohm resistor. The embedded code sets the RTC time, checks the current time, and turns the LED on or off based on the specified time condition (between 11:00 AM and 11:43 AM).
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO Real-Time Clock with DS1307 RTC Module
Image of rrtc: A project utilizing DS1307 RTC in a practical application
This circuit interfaces an Arduino UNO with a DS1307 Real-Time Clock (RTC) module. The Arduino communicates with the RTC module using the I2C protocol, with connections from A4 to SDA and A5 to SCL.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO Controlled Relay with DS3231 RTC
Image of Hooter connections: A project utilizing DS1307 RTC in a practical application
This circuit features an Arduino UNO microcontroller connected to a DS3231 Real Time Clock (RTC) module and a 12V single-channel relay. The Arduino provides power to both the RTC and the relay, and it communicates with the RTC via I2C using the SDA and SCL lines connected to A4 and A5 respectively. The relay is controlled by the Arduino through a digital output on pin D13, allowing the Arduino to switch external loads on and off based on time events managed by the RTC.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Real-Time Clock with I2C LCD Display and IO Expansion
Image of teste: A project utilizing DS1307 RTC in a practical application
This circuit is an Arduino-based real-time clock and display system. It uses an Arduino UNO to interface with a DS1307 RTC module for timekeeping and a 20x4 I2C LCD to display the current time and date. Additionally, a PCF8574 IO Expansion Board is used to extend the I2C bus for additional I/O operations.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with DS1307 RTC

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of li8: A project utilizing DS1307 RTC in a practical application
Arduino UNO with DS1307 RTC Controlled LED Lighting System
This circuit features an Arduino UNO connected to a DS1307 Real Time Clock (RTC) module for timekeeping and a red LED with a series resistor for indication purposes. The Arduino communicates with the RTC via I2C (using A4 and A5 pins for SDA and SCL, respectively), and controls the LED connected to digital pin D8 through a 330-ohm resistor. The embedded code sets the RTC time, checks the current time, and turns the LED on or off based on the specified time condition (between 11:00 AM and 11:43 AM).
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of rrtc: A project utilizing DS1307 RTC in a practical application
Arduino UNO Real-Time Clock with DS1307 RTC Module
This circuit interfaces an Arduino UNO with a DS1307 Real-Time Clock (RTC) module. The Arduino communicates with the RTC module using the I2C protocol, with connections from A4 to SDA and A5 to SCL.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Hooter connections: A project utilizing DS1307 RTC in a practical application
Arduino UNO Controlled Relay with DS3231 RTC
This circuit features an Arduino UNO microcontroller connected to a DS3231 Real Time Clock (RTC) module and a 12V single-channel relay. The Arduino provides power to both the RTC and the relay, and it communicates with the RTC via I2C using the SDA and SCL lines connected to A4 and A5 respectively. The relay is controlled by the Arduino through a digital output on pin D13, allowing the Arduino to switch external loads on and off based on time events managed by the RTC.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of teste: A project utilizing DS1307 RTC in a practical application
Arduino UNO-Based Real-Time Clock with I2C LCD Display and IO Expansion
This circuit is an Arduino-based real-time clock and display system. It uses an Arduino UNO to interface with a DS1307 RTC module for timekeeping and a 20x4 I2C LCD to display the current time and date. Additionally, a PCF8574 IO Expansion Board is used to extend the I2C bus for additional I/O operations.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

  • Digital clocks and timers
  • Data logging systems
  • Home automation projects
  • Alarm systems
  • Microcontroller-based projects requiring accurate timekeeping
  • Wearable devices and IoT applications

Technical Specifications

The DS1307 RTC chip has the following key technical specifications:

Parameter Value
Operating Voltage 4.5V to 5.5V
Backup Battery Voltage 2.0V to 3.5V
Communication Protocol I2C (2-wire)
Timekeeping Accuracy ±2 seconds/day (at 25°C)
Operating Temperature -40°C to +85°C
Current Consumption 1.5µA (typical in battery backup mode)
Clock Format 12-hour or 24-hour
Memory 56 bytes of non-volatile RAM

Pin Configuration and Descriptions

The DS1307 has 8 pins, as described in the table below:

Pin Number Pin Name Description
1 X1 Connect to the external 32.768 kHz crystal oscillator (input).
2 X2 Connect to the external 32.768 kHz crystal oscillator (output).
3 VBAT Backup battery input (2.0V to 3.5V). Maintains timekeeping during power loss.
4 GND Ground (0V reference).
5 SDA Serial Data Line for I2C communication.
6 SCL Serial Clock Line for I2C communication.
7 NC No connection (leave unconnected).
8 VCC Primary power supply (4.5V to 5.5V).

Usage Instructions

How to Use the DS1307 in a Circuit

  1. Power Supply: Connect the VCC pin to a 5V power source and the GND pin to ground. For backup power, connect a 3V coin cell battery to the VBAT pin.
  2. Crystal Oscillator: Attach a 32.768 kHz crystal oscillator to the X1 and X2 pins. No external capacitors are required.
  3. I2C Communication: Connect the SDA and SCL pins to the corresponding I2C pins on your microcontroller. Use pull-up resistors (typically 4.7kΩ) on both lines.
  4. Addressing: The DS1307 has a fixed I2C address of 0x68.
  5. Programming: Use an appropriate library or write custom code to communicate with the DS1307 and set or read the time.

Important Considerations and Best Practices

  • Ensure the backup battery is installed to maintain timekeeping during power outages.
  • Use a high-quality 32.768 kHz crystal oscillator for accurate timekeeping.
  • Avoid placing the crystal oscillator near high-frequency components to minimize interference.
  • Pull-up resistors on the SDA and SCL lines are essential for proper I2C communication.
  • The DS1307 operates in either 12-hour or 24-hour mode. Ensure your code handles the desired format correctly.

Example Code for Arduino UNO

Below is an example of how to use the DS1307 with an Arduino UNO. This code uses the popular RTClib library.

#include <Wire.h>
#include <RTClib.h>

// Create an RTC_DS1307 object to interact with the DS1307 RTC
RTC_DS1307 rtc;

void setup() {
  Serial.begin(9600); // Initialize serial communication at 9600 baud
  Wire.begin();       // Initialize I2C communication

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC. Check connections!");
    while (1); // Halt execution if RTC is not found
  }

  if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running, setting the time...");
    // Set the RTC to the current date and time
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  // Get the current date and time from the RTC
  DateTime now = rtc.now();

  // Print the current date and time to the Serial Monitor
  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();

  delay(1000); // Wait for 1 second before updating
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. RTC Not Detected

    • Cause: Incorrect wiring or missing pull-up resistors on SDA and SCL lines.
    • Solution: Double-check the connections and ensure pull-up resistors (4.7kΩ) are in place.
  2. Time Resets After Power Loss

    • Cause: Backup battery is not connected or is depleted.
    • Solution: Connect a 3V coin cell battery to the VBAT pin and ensure it is functional.
  3. Inaccurate Timekeeping

    • Cause: Poor-quality or improperly connected crystal oscillator.
    • Solution: Use a high-quality 32.768 kHz crystal and ensure proper placement and soldering.
  4. I2C Communication Fails

    • Cause: Incorrect I2C address or conflicting devices on the bus.
    • Solution: Verify the DS1307's I2C address (0x68) and ensure no address conflicts.

FAQs

Q: Can the DS1307 operate without a backup battery?
A: Yes, but it will lose the current time and date when the primary power supply is disconnected.

Q: What is the maximum length for I2C communication lines?
A: The maximum length depends on the pull-up resistor values and the capacitance of the lines, but it is typically limited to a few meters.

Q: Can I use the DS1307 with a 3.3V microcontroller?
A: The DS1307 requires a 5V power supply. However, you can use level shifters to interface it with a 3.3V microcontroller.

Q: How do I switch between 12-hour and 24-hour modes?
A: The hour register in the DS1307 contains a bit to toggle between 12-hour and 24-hour modes. Refer to the datasheet for details on modifying this bit.