The ZS-042 RTC Module is a Real-Time Clock (RTC) module that provides precise timekeeping when embedded in electronic projects. It is based on the DS3231 integrated circuit, which is known for its high accuracy and stability due to its temperature-compensated crystal oscillator. This module is commonly used in applications such as data loggers, alarms, time-stamping events, and digital clocks.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5.5V) |
2 | GND | Ground |
3 | SDA | Serial Data Line for I2C communication |
4 | SCL | Serial Clock Line for I2C communication |
5 | SQW | Square Wave/Interrupt Output |
6 | 32K | 32KHz Output |
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
void setup() {
Wire.begin();
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
// The following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
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);
}
Q: Can the ZS-042 RTC Module work with both 3.3V and 5V systems? A: Yes, the module can operate within a range of 3.3V to 5.5V.
Q: How long will the battery last? A: The CR2032 battery can last for years, depending on the quality of the battery and the environmental conditions.
Q: Is it necessary to use an external crystal with the ZS-042 RTC Module? A: No, the DS3231 IC has an integrated temperature-compensated crystal oscillator.