ArduinoArduino UnoExact chip

Clock (DS1307 + LCD)

RTClib reads a DS1307; the time and date on an I2C LCD.

Clock (DS1307 + LCD) in Argynix Lab

The code

sketch.inoC++
// A DS1307 clock and a 16x2 LCD, both on I2C. RTClib reads the time.
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>

RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  if (!rtc.begin()) {
    lcd.print("No clock found");
    while (true) {
    }
  }
}

void loop() {
  DateTime now = rtc.now();
  char line[17];
  snprintf(line, sizeof(line), "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
  lcd.setCursor(4, 0);
  lcd.print(line);
  snprintf(line, sizeof(line), "%04d-%02d-%02d", now.year(), now.month(), now.day());
  lcd.setCursor(3, 1);
  lcd.print(line);
  Serial.println(line);
  delay(1000);
}