5V
5V
-40C to 85C
-55C to 125C
2 minutes per year
1.5mA (typical) at 5V
I2C
32.768 kHz
2
236 bytes
Pinout
| The DS3231 RTC Module has a 16-pin interface, with the following pinout |
Power input (5V)
Ground
I2C clock input
I2C data input/output
Square wave output (32.768 kHz)
Interrupt output
Battery input (for rechargeable battery backup)
Temperature sensor output
Crystal oscillator input (32.768 kHz)
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.
DS3231 RTC Module (Real Time Clock) DocumentationOverviewThe 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.FeaturesHigh 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 +85CPinout| 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 ExamplesExample 1: Setting and Reading Time using ArduinoThis 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.