Skip to content

Instantly share code, notes, and snippets.

@ichsanputr
Created March 9, 2022 02:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Display current date, hour, second with RTC and LCD Arduino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
lcd.init();
lcd.backlight();
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
}
void loop()
{
DateTime now = rtc.now();
lcd.setCursor(0, 1);
// bye default using UTC time
// add +7 for your local time
lcd.print(now.hour()+7, DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.setCursor(0, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment