RTC3231 SETUP

RTC3231

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/RTC3231%20SETUP.zip

#include <Wire.h> //include Wire.h library
#include “RTClib.h” //include Adafruit RTC library
RTC_DS3231 rtc; //Make a RTC DS3231 object
//Set the names of days
char daysOfTheWeek[7][12] = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”,”Thursday”, “Friday”, “Saturday”};
void setup () {
Serial.begin(9600); //Begin the Serial at 9600 Baud
//Print the message if RTC is not available
if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
while (1);
}
//Setup of time if RTC lost power or time is not set
if (rtc.lostPower()) {
//Sets the code compilation time to RTC DS3231
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop () {
//Set now as RTC time
DateTime now = rtc.now();
//Print RTC time to Serial Monitor
Serial.print(now.year(), DEC);
Serial.print(‘/’);
Serial.print(now.month(), DEC);
Serial.print(‘/’);
Serial.print(now.day(), DEC);
Serial.print(” (“);
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(“) “);
Serial.print(now.hour(), DEC);
Serial.print(‘:’);
Serial.print(now.minute(), DEC);
Serial.print(‘:’);
Serial.println(now.second(), DEC);
delay(100);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s