Stufin
Home Quick Cart Profile

DS3231 RTC Module (Real Time Clock)

Buy Now on Stufin

Operating Voltage

5V

Operating Temperature

-40C to 85C

Storage Temperature

-55C to 125C

Accuracy

2 minutes per year

Power Consumption

1.5mA (typical) at 5V

Communication Protocol

I2C

Clock Frequency

32.768 kHz

Alarm Functions

2

EEPROM Memory

236 bytes

Pinout

The DS3231 RTC Module has a 16-pin interface, with the following pinout

VCC

Power input (5V)

GND

Ground

SCL

I2C clock input

SDA

I2C data input/output

SQW

Square wave output (32.768 kHz)

INT

Interrupt output

BAT

Battery input (for rechargeable battery backup)

TEMP

Temperature sensor output

XTAL

Crystal oscillator input (32.768 kHz)

RST

Reset input

Applications

The DS3231 RTC Module is suitable for a wide range of applications, including

Automation and control systems

Industrial and commercial systems

IoT devices and sensors

Wearable devices and accessories

Hobbyist projects and prototypes

Conclusion

The DS3231 RTC Module is a highly accurate and reliable Real-Time Clock device that provides a precise timing reference for various applications. Its low power consumption, rechargeable battery backup, and built-in temperature sensor make it an ideal choice for a wide range of applications.

Pin Configuration

  • DS3231 RTC Module (Real Time Clock) Pinout Explanation
  • The DS3231 RTC Module is a widely used Real-Time Clock (RTC) component in IoT projects, providing accurate time-keeping capabilities. This documentation explains the pinout of the DS3231 RTC Module, highlighting the function of each pin and how to connect them.
  • Pinout Diagram:
  • Before diving into the pin explanation, here is the standard pinout diagram for the DS3231 RTC Module:
  • ```
  • +-----------+
  • | DS3231 |
  • +-----------+
  • | 1 VCC |
  • | 2 GND |
  • | 3 SCL |
  • | 4 SDA |
  • | 5 SQW |
  • | 6 INT |
  • | 7 RST |
  • +-----------+
  • ```
  • Pin Explanation and Connection Guide:
  • Here is a point-by-point explanation of each pin and how to connect them:
  • 1. VCC (Power Supply)
  • Function: Provides power to the DS3231 RTC Module.
  • Connection: Connect to a 3.3V or 5V power supply, depending on your project's requirements.
  • 2. GND (Ground)
  • Function: Ground pin for the DS3231 RTC Module.
  • Connection: Connect to the ground pin of your power supply or microcontroller.
  • 3. SCL (Serial Clock)
  • Function: Serial clock pin for I2C communication.
  • Connection: Connect to the SCL pin of your microcontroller or I2C bus.
  • 4. SDA (Serial Data)
  • Function: Serial data pin for I2C communication.
  • Connection: Connect to the SDA pin of your microcontroller or I2C bus.
  • 5. SQW (Square Wave Output)
  • Function: Outputs a square wave signal, typically used as a clock signal for other components.
  • Connection: Connect to a pin on your microcontroller or other components that require a clock signal.
  • 6. INT (Interrupt)
  • Function: Interrupt pin, used to signal alarms or events to your microcontroller.
  • Connection: Connect to an interrupt pin on your microcontroller.
  • 7. RST (Reset)
  • Function: Reset pin, used to reset the DS3231 RTC Module.
  • Connection: Connect to a reset pin on your microcontroller or a push-button for manual reset.
  • Important Notes:
  • Make sure to use the correct voltage level (3.3V or 5V) for your project.
  • Use a pull-up resistor on the SCL and SDA lines if not provided by your microcontroller.
  • The SQW pin can be used as a clock signal, but it's not necessary for the RTC module's operation.
  • By following this pinout explanation and connection guide, you should be able to successfully integrate the DS3231 RTC Module into your IoT project.

Code Examples

DS3231 RTC Module (Real Time Clock) Documentation
Overview
The DS3231 RTC Module is a highly accurate, low-power, I2C real-time clock (RTC) module that provides a reliable timing system for various applications. It features a built-in temperature sensor, trickle charger, and a programmable square-wave output.
Features
High accuracy: 2 minutes per year
 I2C interface: supports 400 kHz and 100 kHz bus modes
 Real-time clock (RTC) with seconds, minutes, hours, day, month, year, and century
 Battery-backed SRAM: 236 bytes of user-accessible storage
 Trickle charger: supports rechargeable batteries
 Programmable square-wave output: 1 Hz, 4 kHz, 8 kHz, or 32 kHz
 Temperature sensor: 3C accuracy
 Operating voltage: 3.3V or 5V
 Operating temperature: -40C to +85C
Pinout
| Pin | Function |
| --- | --- |
| VCC | Power supply (3.3V or 5V) |
| GND | Ground |
| SCL | I2C clock |
| SDA | I2C data |
| SQW | Square-wave output |
| BAT | Battery input |
| 32K | 32 kHz output |
Code Examples
Example 1: Setting and Reading Time using Arduino
This example demonstrates how to set and read the time using an Arduino board and the DS3231 RTC Module.
```arduino
#include <Wire.h>
#include <DS3231.h>
DS3231 rtc;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  
  // Set the time to 12:30:00, 21st February 2023
  rtc.setDateTime(2023, 2, 21, 12, 30, 0);
}
void loop() {
  // Read the current time
  DateTime now = rtc.getDateTime();
  
  // Print the current time
  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.println(now.second, DEC);
  
  delay(1000);
}
```
Example 2: Using the DS3231 with a Raspberry Pi (Python)
This example demonstrates how to use the DS3231 RTC Module with a Raspberry Pi using Python.
```python
import smbus
import time
from datetime import datetime
# I2C bus address
I2C_ADDRESS = 0x68
# Create an I2C bus object
bus = smbus.SMBus(1)
def set_time(year, month, day, hour, minute, second):
    # Set the time on the RTC module
    bus.write_i2c_block_data(I2C_ADDRESS, 0x00, [second, minute, hour, day, month, year])
def get_time():
    # Read the time from the RTC module
    data = bus.read_i2c_block_data(I2C_ADDRESS, 0x00, 7)
    return datetime(data[6], data[5], data[4], data[2], data[1], data[0])
# Set the time to 12:30:00, 21st February 2023
set_time(2023, 2, 21, 12, 30, 0)
while True:
    # Read and print the current time
    now = get_time()
    print(now.strftime("%Y-%m-%d %H:%M:%S"))
    time.sleep(1)
```
Note: These examples assume that the DS3231 RTC Module is properly connected to the microcontroller or single-board computer, and that the necessary libraries and dependencies are installed.Consult the specific datasheet and documentation for your platform for more information.