An RTC (real-time clock) module is a digital clock, used to keep track of accurate time even whenever it is located within low power mode or a power supply is turned off. These modules have a controller, a fixed quartz crystal resonator & oscillator. RTCs are designed in an IC form that counts seconds, minutes, hours, days, months & even years so these ICs are used in almost every electronic device particularly when the device needs a form of precise timekeeping like personal computers, embedded systems & servers. There are different RTC modules available in the market like DS3231, DS1307, DS1302, DS1287, etc. This article provides brief information on a DS1307 RTC module like pinout, specifications, interfacing, and its applications.
What is the DS1307 RTC Module?
The DS1307 is a very precise, low-cost, and low-power RTC module that handles the functions of all timekeeping & communicates through the microcontroller above I2C. This module is a full BCD CLK/calendar with 56 bytes of NV SRAM. The data & address in this module are serially transmitted through an I²C and bidirectional bus. The clock/calendar of this module provides information on days, seconds, minutes, hours, dates, months, & years.
The date of month end is adjusted automatically for months by fewer than thirty-one days, with adjustments for leap year. The CLK of this module operates simply in either 12hr or 24hr format by AM or PM indicator. This module includes a power-sense circuit to detect when a power failure occurs and switches automatically to the backup supply. The operation of Timekeeping will continue while it operates with the backup supply.
Pin Configuration:
The pin configuration of the DS1307 RTC module is shown below. This module includes 8 pins which are discussed below.
- Pins 1 & 2 (X1, X2): The crystal oscillator must be allied to these two pins.
- Pin3 (V-Bat): This pin is connected to the battery’s Positive terminal which means it is a backup input supply for any normal 3Volts lithium cell to keep precise timekeeping once the main power supply to the device is disrupted.
- Pin4 (GND): It is the GND pin or negative power input pin of the RTC IC.
- Pin5 (VCC): It is a positive (+ve) power input pin that ranges from 3.3V – 5.5V.
- Pins6 (SCL & SDA): The SCL pin is a CLK input I2C serial communication pin used for synchronizing the movement of data on the serial interface whereas the SDA pin is mainly used for the data I/O for the I2C serial interface.
- Pin7 (SQW/Out): This pin is used for obtaining square wave frequencies like; 1Hz, 4kHz, 8 kHz, (or) 32 kHz & is programmatically possible.
Features & Specifications:
The features and specifications of the DS1307 RTC Module include the following.
- The operating voltage of the DS1307 RTC module is 5V.
- These modules are available in an 8-pin SOIC/DIP package.
- It has a Two-wire I2C interface.
- It has 1Hz of output pin.
- It consumes < 500nA of power within the mode of battery backup through oscillator running.
- It has Non-volatile memory with 56 Bytes for storage of data.
- This module is completely pre-programmed with the present time.
- This module manages totally all the functions of timekeeping.
- Compensation Valid Up to 210056-Byte,
- This RTC module is battery-backed.
- For most of the microcontrollers, it has simple serial port interfaces.
- This module has automatic power-fail detect & switch circuitry.
DS1307 RTC Module Components
The DS1307 RTC module includes five essential components; DS1307 RTC IC, 24C32 EEPROM chip, 32 kHz crystal oscillator, battery holder & DS18B20 temperature sensor soldering place which are explained below.
32kHz Crystal Oscillator
DS1307 RTC module consists of a 32 kHz crystal oscillator which is connected in between the pins 1 and 2. This oscillator simply provides frequency to the chip to perform time-keeping functions. However, the external temperature will affect the oscillation frequency of these crystals. So this change within the oscillation frequency can be insignificant although it adds up surely.
24C32 EEPROM IC
The RTC module is available with a 32-byte Atmel 24C32 EEPROM chip that has limited read-write cycles. This EEPROM chip saves settings (or) clock/calendar. This IC utilizes the I2C interface used for communication & shares a similar I2C bus to the DS1307 IC.
Battery Holder
The RTC module has a battery holder at the bottom for a 3V 20mm lithium coin cell. In this battery holder, any CR2032 type battery. Once the main power is interrupted to the module then an in-built power-sense circuit checks the condition of the input power supply continuously for detecting power failures & switches automatically to the backup power supply. Thus, it maintains the date & time continuously when the power to the device is incorrect. The DS1307 IC includes a battery input & maintains precise timekeeping
Soldering Place for DS18B20 Sensor
This RTC module has a soldering place for a DS18B20 temperature sensor. This module includes three holes in the left corner next to the holder of the battery where we can solder the sensor. If you mount this sensor then you can get the readings of temperature from the DS pin, so this can be utilized in time drift projects based on temperature.
DS1307 RTC Module Interfacing with Arduino Uno
The DS1307 RTC module interfacing with the Arduino Uno board is shown below. The required components to make this interfacing mainly include; a DS1307 RTC module, jumper wires, and Arduino Uno. The connections of this interfacing follow as;
- The A5 pin of Arduino Uno is connected to the SCL pin of the DS1307 RTC module.
- The A4 pin of Arduino Uno is connected to the SDA pin of the module.
- The 5V pin of Arduino Uno is connected to the VCC pin of the module.
- The GND pin of Arduino Uno is connected to the GND pin module.
Code
The required code for this interfacing is shown and discussed below.
Before you start coding, you need to install the DS1307 library if you haven’t already. You can do this through the Arduino IDE.
- Open the Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries…
- In the Library Manager, type “DS1307” in the search bar.
- Look for the “DS1307RTC” library by Michael Margolis and install it.
#include <Wire.h>
#include <DS1307RTC.h>
void setup() {
Serial.begin(9600);
// Check if the RTC is connected properly
if (!RTC.isRunning()) {
Serial.println(“RTC is NOT running!”);
// Set the time (uncomment and set the time when uploading for the first time);
RTC.set(now());
} else {
Serial.println(“RTC is running.”);
}
}
void loop() {
// Get the current time
tmElements_t tm;
if (RTC.read(tm)) {
// Print the time in HH:MM:SS format
Serial.print(“Time: “);
Serial.print(tm.Hour);
Serial.print(“:”);
Serial.print(tm.Minute);
Serial.print(“:”);
Serial.println(tm.Second);
// Wait for one second
delay(1000);
} else {
// Print an error message if reading the time fails
Serial.println(“Error reading time from RTC!”);
delay(1000);
}
}
Working
Once the connections are made according to the interfacing DS1307 RTC module with Arduino as shown above, then upload the code in your Arduino Uno. Open the serial monitor to observe the readings of the time, date, etc. This can be used in digital clocks for recording data like seconds, hours, minutes, days, months, dates & years.
Applications
The applications of the DS1307 RTC module include the following.
- The RTC module is used in real-time systems which include; a digital clock, digital cameras & attendance systems.
- This module is a good choice wherever a timestamp is necessary.
- This module is used to handle all the functions of timekeeping & communication through the microcontroller.
- This DS1307 module keeps track of seconds, minutes, hours, days, dates, months & years.
- It is used to make a real-time clock, DIY projects, electronic & electrical projects, robotics projects, Raspberry Pi projects, and Arduino projects.
- These modules are used in servers, gaming, robotics, GPS, computer peripherals, utility power meters, etc.
Please refer to this link for DS1307 RTC Module Datasheet.
Thus, this is an overview of the DS1307 RTC module, pin configuration, specifications, interfacing, and its applications. These RTC modules have an in-built power-sense circuit to notice power failures & it switches automatically to the backup power supply. The operation of Timekeeping will continue while the module works from the backup supply. This module has a battery backup arrangement to keep the clock or calendar running when there is no power and this module uses very little current. Here is a question for you, what is DS3231?