In this lesson, I've explained Real Time clock with serial i2c module (Figure 1), Arduino UNO and DS3231 module (Figure 2).
Figure 1 - Serial I2C LCD Module
Figure 2 - DS3231 Module
The DS3231 is a low-cost, highly accurate Real Time Clock which can maintain hours, minutes and seconds, as well as, day, month and year information. Also, it has automatic compensation for leap-years and for months with fewer than 31 days. The module can work on either 3.3 or 5 V which makes it suitable for many development platforms or microcontrollers. The battery input is 3V and a typical CR2032 3V battery can power the module and maintain the information for more than a year.
Module pins are connected with Arduino as follows;
SDA (A4); SCL(A5); VCC(5V veya Vin); GND(GND)
Figure 3 - Real Time Clock Circuit
The Program of Arduino UNO
#include <Wire.h> // For the i2c devices (i2C modülü için)
#include <LiquidCrystal_I2C.h> // For the LCD Display (LCD Ekran için)
#include "RTClib.h" // For Real Time Clock (Gerçek Zamanlı saat için)
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Paz", "Pzt", "Sal", "Car", "Per", "Cum", "Cmt"}; //Days of week (Haftanın günleri)
LiquidCrystal_I2C lcd(0x27,16,2);//A4 and A5 Arduino port for SLC adn SLA
void setup()
{
Wire.begin();
lcd.begin();
}
void loop()
{
DateTime now = rtc.now(); //Now (Şimdiki Tarih ve Zaman)
lcd.backlight();
// Date(Tarih)
lcd.setCursor(0,0);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
//Days of week (Haftanın Günü)
lcd.setCursor(11,0);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
//Time (Saat)
lcd.setCursor(0,1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
delay(1000); // 1 second (1 Saniye)
}
Project Files
Hiç yorum yok:
Yorum Gönder