โมดูล DS3231 Real Time Clock เป็นโมดูลไว้สำหรับให้ MCU ผ่าน I2C ซึ่งสามารถดึงค่า วัน เวลา ชั่วโมง นาที วินาทีวันของสัปดาห์ และอุณหภูมิ มาใช้แสดง Alarm หรือ ตั้งเวลา Time Stamp Data Logger
ส่วนประกอบของโมดูล
แบตเตอร์รี่ 3 v ไว้สำหรับเลี้ยงโมดูลเมื่อไม่ได้ต่อไฟเลี้ยง 5V
IC AT24C32 และ DS3231
การ Wiring
GND >> GND
VCC>> +5V
SDA>> A4
SCL>>A5
โหลด Library สำหรับ DS3231 จากลิ้งค์
https://dl.dropboxusercontent.com/u/13758529/elec2you/Library/ModuleDS3231/RTClib.rar
Datasheet
https://dl.dropboxusercontent.com/u/13758529/elec2you/Datasheet/DS3231-102175.pdf
ตัวอย่างโปรแกรม
// Date, Time and Alarm functions using a DS3231 RTC connected via I2C and Wire lib
#include
#include // not used here, but needed to prevent a RTClib compile error
#include
RTC_DS3231 RTC;
void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
DateTime now = RTC.now();
RTC.setAlarm1Simple(21, 58);
RTC.turnOnAlarm(1);
if (RTC.checkAlarmEnabled(1)) {
Serial.println("Alarm Enabled");
}
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
if (RTC.checkIfAlarm(1)) {
Serial.println("Alarm Triggered");
}
Serial.println();
Serial.print("Tempeature = ");
Serial.print(RTC.getTemperature());
Serial.println(" C*");
Serial.println("www.elec2you.com");
Serial.println();
delay(3000);
}
เมื่อเปิด Serial Monitor
ขอบคุณครับ ที่แวะมาอุดหนุนทางร้าน