4D LearningFRC 6429 4th Dimension

Arduino deneyi 20

Mini Digital Clock

Intermediate · 75 min · I²C and timekeeping

Read time from a DS3231 real-time clock and show it on an I²C LCD.

Sesli anlatım videosu (İngilizce, sentetik ses). Çekim videosu eklenince yerini alır.

Malzemeler

  • Arduino Uno
  • DS3231 RTC module
  • 16×2 I²C LCD
  • Jumper wires
  • RTClib and LiquidCrystal_I2C libraries

Bağlantı

  1. Connect both modules to 5V and GND.
  2. Connect both SDA pins to A4 and both SCL pins to A5 on the Uno.
  3. Check the LCD address with an I²C scanner; 0x27 is common.

Kod

#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.init(); lcd.backlight();
  if (!rtc.begin()) { lcd.print("RTC not found"); while (true) {} }
  // Run once if needed, then comment out and upload again:
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  DateTime now = rtc.now();
  lcd.setCursor(0,0);
  if (now.hour()<10) lcd.print('0'); lcd.print(now.hour()); lcd.print(':');
  if (now.minute()<10) lcd.print('0'); lcd.print(now.minute()); lcd.print(':');
  if (now.second()<10) lcd.print('0'); lcd.print(now.second());
  lcd.setCursor(0,1);
  lcd.print(now.day()); lcd.print('/'); lcd.print(now.month()); lcd.print('/'); lcd.print(now.year());
  delay(500);
}

Ne olmalı?

The LCD displays the current time and date while the RTC keeps time when unplugged.

Meydan okuma

Add two buttons to choose between clock and temperature views.

Güvenlik ve sorun giderme

  • Bağlantıyı değiştirmeden önce gücü kes.
  • Her LED ile direnç kullan.
  • Kart ve port seçimini Arduino IDE'de kontrol et.
  • Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.

Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.