Arduino uno
1602 LCD display
A-Ds1307 clock module
jumper wires
For LCD display
VCC = 5V
GND = GND
SDA = A4
SCL = A5
For clock module
GND = GND
VCC = 5V
SDA = A4
SCL =A5
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SI2C.h>
#include <RTClib.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
void setup ()
{
Serial.begin(9600);
lcd.begin (16,2); // initialize the lcd
lcd.backlight();//To Power ON the back light
if (! rtc.begin())
{
lcd.print("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning())
{
lcd.print("RTC is NOT running!");
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));//auto update from computer time
//rtc.adjust(DateTime(2020, 1, 21, 3, 0, 0));// to set the time manualy
}
void loop ()
{
DateTime now = rtc.now();
lcd.setCursor(0, 1);
lcd.print("TIME");
lcd.print(" ");
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("DATE");
lcd.print(" ");
//lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
//lcd.print(" ");
lcd.print(now.day());
lcd.print('/');
lcd.print(now.month());
lcd.print('/');
lcd.print(now.year());
lcd.print(" ");
}