microrobotics icon

Untitled

microrobotics | PRO | 07/13/23 11:49:34 AM UTC | 0 ⭐ | 10147 👁️ | Never ⏰ | [DS3231, RTC]
Arduino |

810 B

|

None

|

0 👍

/

0 👎

#include <Wire.h>
#include "RTClib.h"
 
RTC_DS3231 rtc;
 
void setup() {
  Serial.begin(9600);
  Wire.begin();
  
  // Check if the DS3231 module is connected
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  
  // Uncomment the line below to set the time on the DS3231 module
  // 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();
  
  delay(1000);
}

Comments