Electronics

Real Time Clock RTC Module AT24C32 Ds3231

AED 21.50

1

Description

the DS3231 Real-Time Clock Module is a powerful and cost-effective timekeeping solution that brings accuracy, reliability, and flexibility to a wide array of applications. Whether you're working with servers, GPS devices, data loggers, or any other time-critical system, the DS3231 is sure to elevate performance and deliver precise results every time.

 

Package Includes:

  • 1 x DS3231 Real-Time Clock Module

 

Features:

  • Compact Size: The module is designed to be compact and space-efficient, measuring 38mm in length, 22mm in width, and 14mm in height. This small form factor makes it suitable for applications with limited space.
  • Lightweight: Weighing only 8g, the module is lightweight, ensuring it adds minimal burden to your projects and devices.
  • Wide Operating Voltage Range: The module can operate within a voltage range of 3.3V to 5.5V, providing flexibility in power supply options and compatibility with various devices.
  • High-Precision Clock Chip: Powered by the DS3231 high-precision clock chip, the module ensures accurate and reliable timekeeping.
  • Impressive Clock Accuracy: Within the temperature range of 0-40°C, the module achieves a remarkable accuracy of 2 parts per million (ppm), resulting in an error of approximately 1 minute.
  • Dual Calendar Alarm Clock: Equipped with two alarm clocks, the module allows you to set and manage multiple alarms for different time-sensitive events.
  • Programmable Square-Wave Output: The module offers a programmable square-wave output, which can be used for generating periodic signals or synchronization purposes.
  • Real-Time Clock Generator: The module acts as a real-time clock generator, capable of tracking seconds, minutes, hours, days, dates, months, and years with precision. It can provide accurate timekeeping up to the year 2100, and it also compensates for leap years.
  • Built-in Temperature Sensor: With an integrated temperature sensor, the module can measure and provide temperature data with an accuracy of 3°C.
  • Ample Memory Storage: The module includes an AT24C32 memory chip, offering a generous storage capacity of 32K, allowing you to store essential data and settings.
  • IIC Bus Interface: The module supports communication through the IIC (Inter-Integrated Circuit) bus interface, which enables easy and efficient data exchange with other compatible devices.
  • Cascading Capability: It can be cascaded with other IIC devices, allowing for expanded functionality and enhanced performance in interconnected systems. The 24C32 addresses can be modified to suit specific configurations, with the default address set at 0x57.

 

Description:

The DS3231 is a versatile and indispensable timekeeping device, an Integrated Circuit (IC) that brings precision and reliability to a multitude of time-critical applications and devices. Its robust design and remarkable accuracy make it an ideal choice for various systems such as Servers, GPS units, Data Loggers, and more. At its core, the DS3231 boasts a low-cost, yet incredibly accurate I2C real-time clock, featuring an integrated temperature-compensated crystal oscillator (TCXO) and crystal. Unlike its predecessor, the DS1302, the DS3231 excels with a wide voltage operating range of 2.3V to 5.5V, making it adaptable to various power supply configurations. Moreover, with its built-in battery backup, the DS3231 ensures uninterrupted timekeeping even during power outages, safeguarding your critical data and time-sensitive applications. One of the DS3231's standout features is its integrated crystal, eliminating the need for an external crystal. Additionally, the module includes a temperature sensor, enabling accurate temperature readings alongside precise timekeeping, making it ideal for applications where temperature data is crucial. Enhancing its versatility, the DS3231 is equipped with two programmable time-of-day alarms, allowing you to schedule specific events or actions with ease. Moreover, the 32.768 kHz output pin enhances overall accuracy, ensuring your time-sensitive tasks are performed with unmatched precision. To complement the already impressive capabilities, the module is further enriched with an EEPROM AT24C32, providing a generous 32K EEPROM to store and retrieve your data efficiently. With a built-in battery holder, this module offers an excellent solution for recording time-related information and is a superior alternative to data logging shields, providing even higher time precision.

 

Principle of Work:

The DS3231 Real-Time Clock (RTC) module is built around the DS3231 IC, which is a highly integrated RTC chip manufactured by Maxim Integrated. The module consists of various components that work together to provide accurate timekeeping and additional functionalities.

Internally, the DS3231 IC contains several key components:

  1. Crystal Oscillator: The DS3231 has a built-in temperature-compensated crystal oscillator (TCXO). The crystal generates precise clock pulses, which serve as the basis for timekeeping. The TCXO compensates for temperature variations, ensuring accurate timekeeping across different temperature ranges.
  2. RTC Counter and Registers: The IC contains counters and registers to keep track of time. It maintains the current time in hours, minutes, seconds, day, date, month, and year. These values are updated continuously based on the clock pulses from the crystal oscillator.
  3. Temperature Sensor: The DS3231 includes a built-in temperature sensor that measures the ambient temperature. This temperature data can be accessed by the microcontroller or MCU connected to the module, allowing temperature monitoring in addition to timekeeping.
  4. Control Logic: The IC features control logic to handle various operations and functionalities. It manages alarms, output signals, and communication with the MCU.
  5. I2C Interface: The DS3231 communicates with the MCU using the I2C (Inter-Integrated Circuit) protocol. The I2C interface allows bi-directional serial communication between the DS3231 and the MCU. The MCU can read and write data to control the DS3231's functions and retrieve time and temperature data.

How the module works with MCU:

When the DS3231 RTC module is connected to a microcontroller (MCU), typically through the I2C interface, the MCU can interact with the DS3231 to perform various tasks:

  1. Initialization: The MCU initializes the DS3231 by configuring its settings, such as setting the time, enabling alarms, and adjusting other parameters.
  2. Timekeeping: The DS3231 continuously keeps track of time and updates its internal registers (seconds, minutes, hours, etc.) based on the clock pulses from the crystal oscillator. The MCU can read these values to obtain the current time.
  3. Temperature Monitoring: The MCU can read the temperature sensor data from the DS3231 to monitor the ambient temperature. This information can be used for temperature compensation or other temperature-related functionalities.
  4. Alarms: The DS3231 has two programmable alarms that can be set by the MCU. The MCU can configure the alarms to trigger specific actions or events at predetermined times.
  5. Communication: The MCU and DS3231 communicate using the I2C protocol. The MCU acts as the master and sends commands or requests to the DS3231, while the DS3231 acts as the slave and responds accordingly.
  6. Battery Backup: In case of a power failure, the DS3231's battery backup ensures that timekeeping continues uninterrupted. The MCU can also monitor the status of the battery backup to detect power loss events.

 

 

Pinout of the Module:

 

 

  1. VCC: Power supply voltage pin (3.3V to 5.5V).
  2. GND: Ground pin, connected to the ground of the system.
  3. SDA: I2C data pin for communication with other devices.
  4. SCL: I2C clock pin for synchronizing communication with other devices.
  5. SQW/OUT: Square wave or output pin that can be programmed to generate periodic signals.
  6. 32kHz: Output pin for the 32.768 kHz clock signal (used for timekeeping accuracy).
 

Applications:

  • Real-Time Clock for Electronic Devices: The DS3231 module is commonly used as a real-time clock in electronic devices like digital clocks, timers, watches, and wall clocks to provide accurate and reliable timekeeping.
  • Data Loggers and Time-Stamped Data: Its high precision makes it suitable for data logging applications where time-stamped data is crucial, such as environmental monitoring, temperature logging, and event tracking.
  • Servers and Network Equipment: In servers and network equipment, the DS3231 helps maintain accurate time for synchronization, logging events, and data analysis.
  • Automotive Applications: The module is used in automotive systems for precise timekeeping, dashboard clocks, and event logging.
  • GPS Devices: In GPS devices, the DS3231 module is utilized to maintain accurate time, which is essential for proper GPS functioning and positioning.
  • Security Systems: Security systems rely on accurate timekeeping for event logging, access control, and scheduling operations, making the DS3231 a suitable component for such applications.
  • Home Automation: In home automation systems, the DS3231 module is used for scheduling tasks, managing lighting, and coordinating various smart devices.
  • Industrial Automation: Industrial automation applications utilize the DS3231 for scheduling processes, logging data, and coordinating events in precise time intervals.
  • Internet of Things (IoT) Devices: IoT devices often require accurate timekeeping for synchronization and data recording, making the DS3231 a popular choice for such applications.
  • Medical Devices: Medical equipment and devices often require precise timing for patient monitoring, data recording, and event tracking, making the DS3231 a valuable component in medical applications.
  • Communication Equipment: The DS3231 is used in communication equipment for accurate timing, synchronization, and event logging in telecommunications and networking.
  • Weather Stations: Weather stations and environmental monitoring systems benefit from the DS3231 module's time accuracy for recording weather data at specific intervals.

 

Circuit:

 

 

Library:

To upload the DS3231 RTC module library to the Arduino IDE, follow these steps:

  1. Download the Library:

  2. Install the Library in Arduino IDE:

    • Open the Arduino IDE on your computer.
    • Go to "Sketch" in the top menu, then select "Include Library" and click on "Add .ZIP Library."
    • Navigate to the downloaded DS3231_RTC_Module.zip file and select it.
    • The Arduino IDE will automatically install the library, and you should see a message confirming the successful installation.
  3. Verify Library Installation:

    • To verify that the library has been installed correctly, go to "Sketch" in the top menu, then select "Include Library." You should now see "DS3231 RTC Module" listed under "Contributed Libraries."

 

Code:

This code is for initializing and interfacing with a DS3231 Real-Time Clock (RTC) module. it sets the initial date and time on the DS3231 module and then continuously read the current date and time from the module and displays it on the serial monitor.

#include "Wire.h"
#include "ds3231.h"

struct ts t;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  DS3231_init(DS3231_CONTROL_INTCN);

  // Set the initial time and date values
  setInitialDateTime(2020, 11, 14, 3, 0, 0);
}

void loop() {
  // Get the current time and date from the DS3231 module
  DS3231_get(&t);

  // Print the date and time to the serial monitor
  printDateTime(t);

  delay(1000);
}

// Function to set the initial time and date values
void setInitialDateTime(int year, int month, int day, int hour, int minute, int second) {
  t.year = year;
  t.mon = month;
  t.mday = day;
  t.hour = hour;
  t.min = minute;
  t.sec = second;

  DS3231_set(t);
}

// Function to print the date and time to the serial monitor
void printDateTime(struct ts t) {
  Serial.print("Date: ");
  Serial.print(t.mday);
  Serial.print("/");
  Serial.print(t.mon);
  Serial.print("/");
  Serial.print(t.year);
  Serial.print("\t Hour: ");
  Serial.print(t.hour);
  Serial.print(":");
  Serial.print(t.min);
  Serial.print(".");
  Serial.println(t.sec);
}

  1. The code includes necessary libraries, Wire.h for I2C communication and ds3231.h for DS3231 RTC functionality.

  2. A structure ts is defined to hold date and time information.

  3. In the setup() function:

    • Serial communication is initialized with a baud rate of 9600 using Serial.begin(9600).
    • The I2C bus is started with Wire.begin().
    • The DS3231 RTC module is initialized with DS3231_init(DS3231_CONTROL_INTCN), which sets the module's control settings. The DS3231_CONTROL_INTCN constant is likely used to enable the output signal, such as the square wave.
  4. The setInitialDateTime function is called to set the initial date and time on the DS3231 module. In this case, it sets the initial date and time to 3:00:00 AM on November 14, 2020.

  5. In the loop() function:

    • The current date and time from the DS3231 module are obtained and stored in the t structure using DS3231_get(&t). This function fetches the data from the RTC and stores it in the t structure, so you can work with it.
    • The printDateTime function is called to display the date and time information on the serial monitor.
  6. The printDateTime function takes the t structure containing date and time information as input and prints it on the serial monitor. It formats the data to display the date in the "dd/mm/yyyy" format and the time in the "hh:mm.ss" format.

  7. A delay of 1000 milliseconds (1 second) is added using delay(1000) to create a one-second interval between each reading and display of the date and time on the serial monitor.

 

Technical Details:

  • Size: 38mm (length) * 22mm (width) * 14mm (height)
  • Weight: 8g
  • Operating Voltage: 3.3V to 5.5V
  • Clock Chip: DS3231, a high-precision clock chip
  • Clock Accuracy: Within the range of 0-40℃, the accuracy is 2ppm, resulting in an error of about 1 minute
  • Calendar: Equipped with two alarm clocks
  • Square-Wave Output: Programmable square-wave output
  • Real-Time Clock Generator: Capable of tracking seconds, minutes, hours, days, dates, months, and years. It provides accurate timing up to the year 2100 and includes leap-year compensation.
  • Temperature Sensor: Integrated chip temperature sensor with an accuracy of 3℃
  • Memory Chip: AT24C32 with a storage capacity of 32K
  • IIC Bus Interface: Supports IIC bus communication with a maximum transmission speed of 400KHz (at a working voltage of 5V)
  • Cascading Capability: Can be cascaded with other IIC devices, and the 24C32 addresses can be modified by shorting A0/A1/A2 pins. The default address is set at 0x57.

 

 

Resources:

 

Comparisons:

The DS3231 and DS1307 are both popular Real-Time Clock (RTC) modules manufactured by Maxim Integrated, the DS3231 offers higher accuracy, temperature compensation, and more advanced features compared to the DS1307. The DS3231 is often preferred for applications that require precise timekeeping and temperature monitoring. However, the DS1307 is still a cost-effective option for less critical timekeeping applications with moderate accuracy requirements:

  1. Accuracy:

    • DS3231: The DS3231 is known for its high accuracy. It has an accuracy of 2 parts per million (ppm) within the temperature range of 0 to 40 degrees Celsius, resulting in an error of about 1 minute per year.
    • DS1307: The DS1307 is less accurate compared to the DS3231. It typically has an accuracy of around 20 parts per million, resulting in a higher time drift over time.
  2. Temperature Compensation:

    • DS3231: The DS3231 incorporates a temperature-compensated crystal oscillator (TCXO), which helps maintain accurate timekeeping across different temperature ranges.
    • DS1307: The DS1307 does not have a temperature-compensated oscillator, which can lead to slightly less accurate timekeeping under varying temperatures.
  3. Integrated Crystal:

    • DS3231: The DS3231 has an integrated crystal oscillator, meaning it does not require an external crystal for its operation.
    • DS1307: The DS1307 requires an external 32.768 kHz crystal for its timekeeping.
  4. Alarm Functionality:

    • DS3231: The DS3231 has two programmable time-of-day alarms, allowing you to set specific events or actions at predetermined times.
    • DS1307: The DS1307 has one programmable alarm, providing limited alarm functionality compared to the DS3231.
  5. Temperature Sensor:

    • DS3231: The DS3231 includes a built-in temperature sensor, allowing you to monitor the ambient temperature in addition to timekeeping.
    • DS1307: The DS1307 does not have an integrated temperature sensor.
  6. Voltage Range:

    • DS3231: The DS3231 operates over a wider voltage range, typically from 2.3V to 5.5V.
    • DS1307: The DS1307 operates from 4.5V to 5.5V, which is more limited compared to the DS3231.
  7. Memory Capacity:

    • Both modules have a similar amount of memory capacity. The DS3231 and DS1307 often come with an EEPROM memory chip of 32K (AT24C32) to store additional data.