Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →How to make Arduino remember the time and date even after disconnecting power.
SDA to A4 and SCL to A5, like other I2C modules.
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600);
if (!rtc.begin()) { Serial.println("RTC FAIL"); return; }
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // يضبطه وقت الرفع
}
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.hour()); Serial.print(':'); Serial.println(now.minute());
delay(1000);
}Expecting the RTC to automatically compensate for lost time without a 3V battery (CR2032) — the battery is the cornerstone of this component.