🛠 RTC timestamps and a minute alarm (no battery!)

Arduino UNO R4 Minima · intermediaire · Schéma : IMG-uno-r4-minima-intermediaire-2-rtc-alarme-sans-pile.svg — UNO R4 Minima avec RTC RA4M1 annoté, LED sur pin 13, moniteur série affichant un horodatage ISO, icône batterie barrée pour le RTC.

Goal

Use the RA4M1 real-time clock to keep time, print a timestamp on every minute change, and fire an event (LED + serial line) as an alarm. Caveat up front: the board has no backup battery, so the clock restarts from the sketch value at every boot.

Code

#include "RTC.h"
RTCtime now;
uint8_t lastMinute = 255;

void setup {
  Serial.begin(115200);
  RTC.begin;
  RTCtime t(2026, 10, 14, 8, 0, 0);  // Y M D H M S, set once per boot
  RTC.set(t);
}

void loop {
  RTC.get(now);
  if (now.minute != lastMinute) {
    lastMinute = now.minute;
    Serial.printf("%04d-%02d-%02d %02d:%02d:%02d\n",
      now.year, now.month, now.dayofmonth,
      now.hour, now.minute, now.second);
    digitalWrite(13, !digitalRead(13));  // blink each minute
  }
  delay(100);
}

Expected result

One timestamp line per minute, LED toggling with it. Poll faster than once per minute or you will miss boundaries.

Common mistakes

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials