Sincronizar hora de RTC DS3231 con arduino UNo

Hi everyone

I am trying to make an alarm using RTC DS3231 but I have not could do it because I can’t assign the time in RTC to Arduino board.
Would you help me?
Thank you in advance.

#include <Time.h>
#include <TimeAlarms.h>
#include<Wire.h>
#include<RTClib.h>

//Declaramos un RTC DS3231
RTC_DS3231 rtc;

void setup() {
Serial.begin(9600);

//Comprobamos si el RTC esta conectado
if(! rtc.begin()){
Serial.println("No hay modulo RTC");
while(1);
}
//Ponemos la fecha y hora(año, dia, mes, hora, minutos, segundos)
rtc.adjust(DateTime(2021, 18, 8, 1, 0, 0));

//setSyncProvider(rtc.get);
// if (timeStatus() != timeSet)
// Serial.println("Fallo de RTC");
// else
// Serial.println("Sincronizado con RTC");

// Crear las alarmas y configurar las funciones correspondientes a cada una
Alarm.alarmRepeat(1, 1, 0, Alarma); // Evento a las 1:1:0
}

void loop() {
//Asignamos la hora al arduino a traves del RTC
//DateTime now = rtc.now();

// Mostrar el reloj en el monitor serial
digitalClockDisplay();

// Para procesar las alarmas
Alarm.delay(1000);
}

void Alarma()
{
Serial.println("Evento a las 1:1:0");
}

/**
Funciones para la impresion del reloj al monitor serial de arduino
*/
void digitalClockDisplay() {
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits) {
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);

Please follow the advice given in the link below when posting code . Use code tags when posting code here to make it easier to read and copy for examination

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.