The Adafruit PCF8523 RTC is a Real Time Clock (RTC) module that offers precise timekeeping capabilities. It is designed to maintain accurate time with the help of a built-in crystal oscillator and can continue to keep time with a backup battery even when the main power supply is disconnected. This component is ideal for a variety of applications, including data loggers, alarm systems, and other time-sensitive projects.
Common applications and use cases:
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (1.8V to 5.5V) |
2 | GND | Ground connection |
3 | SDA | I2C Data Line |
4 | SCL | I2C Clock Line |
5 | INT | Interrupt output (active low) |
6 | CLKOUT | Clock output for peripheral devices |
#include <Wire.h>
#include "RTClib.h"
RTC_PCF8523 rtc;
void setup() {
Wire.begin();
Serial.begin(9600);
// Check if the RTC is connected correctly
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// Check if the RTC has lost power and if so, set the time
if (!rtc.initialized() || rtc.lostPower()) {
Serial.println("RTC is NOT initialized, let's set the time!");
// This 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();
// Print the current date and 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.print(now.second(), DEC);
Serial.println();
// Wait for a second
delay(1000);
}
Q: Can the PCF8523 RTC module be used with a 3.3V system? A: Yes, the module can operate from 1.8V to 5.5V, making it suitable for both 3.3V and 5V systems.
Q: How long will the backup battery last? A: The battery life depends on the quality of the battery and the environmental conditions but typically lasts for a few years.
Q: Is it necessary to use an external crystal with the PCF8523 RTC? A: No, the PCF8523 has an integrated crystal oscillator that provides accurate timekeeping.