โมดูลนาฬิกา DS3231 module ความแม่นยำสูง RTC DS3231 AT24C32 IIC Module Precision Clock Module for Arduino DS3231 module
บทความนี้แสดงการทดสอบ RTC DS3231 ด้วย Arduino Pro Mini
การ Wiring
1. GND ---- GND
2. VCC---- +5V
3. SDA----A4
4. SCL----A5
Code
// 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);
}
ตัวอย่าง VDO การทดสอบ
ขอบคุณครับ ที่แวะมาอุดหนุนทางร้าน