#include <RTClib.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display
char t[32];
float temperature;
void setup()
{
Serial.begin(9600);
Wire.begin();
lcd.begin(20, 4); // Initialize the LCD display with 20 columns and 4 rows
lcd.backlight();
rtc.begin();
rtc.adjust(DateTime(2024, 4, 2, 12, 07, 56)); // Set the desired date and time
}
void loop()
{
DateTime now = rtc.now();
sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
lcd.setCursor(0, 0);
lcd.print("Date/Time: ");
lcd.setCursor(0, 1);
lcd.print(t);
temperature = rtc.getTemperature();
lcd.setCursor(0, 2);
lcd.print("Temperature: ");
lcd.print(temperature);
lcd.print(" C");
delay(1000);
}