Skip to content
Snippets Groups Projects
Commit 0caa66b6 authored by Khin Zin Zin  Thin's avatar Khin Zin Zin Thin
Browse files

add final project 및 보고서pdf

parent 5adfa2d6
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -21,6 +21,7 @@ RTC_DS3231 rtc;
// --- 전역 변수 ---
int riskScore = 0;
String statusText = "";
unsigned long bootTime;
// --- Common Anode (VCC) LED용 반전 RGB 출력 ---
void setRGB(int r, int g, int b) {
......@@ -43,6 +44,8 @@ void setup() {
pinMode(BLUE_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
bootTime = millis(); // 시스템 시작 시간 기록
if (rtc.lostPower()) {
Serial.println("RTC had lost power. Setting time...");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // 현재 컴퓨터 시간으로 설정
......@@ -61,9 +64,14 @@ void loop() {
// --- 위험도 판단 ---
riskScore = 0;
if (temp > 30 || hum > 80) riskScore += 2;
if (light < 200) riskScore += 1;
if (light > 800) riskScore += 1;
// 시스템 시작 후 5초가 지난 경우에만 PIR 조건 적용
if (millis() - bootTime > 5000) {
if (pir == HIGH && (hour >= 20 || hour < 6)) riskScore += 2;
}
// 상태 판단 및 출력
if (riskScore >= 4) {
statusText = "Danger";
setRGB(255, 0, 0);
......@@ -71,18 +79,18 @@ void loop() {
tone(BUZZER_PIN, 1000); delay(300);
noTone(BUZZER_PIN); delay(200);
}
} else if (riskScore >= 2 && riskScore < 4) {
} else if (riskScore >= 2) {
statusText = "Warning";
setRGB(255, 150, 0);
tone(BUZZER_PIN, 600); delay(200); noTone(BUZZER_PIN); delay(200);
tone(BUZZER_PIN, 600); delay(200); noTone(BUZZER_PIN);
} else {
statusText = "Normal";
setRGB(0, 255, 0); // 초록
setRGB(0, 255, 0);
noTone(BUZZER_PIN);
}
// --- LCD 출력 ---
// LCD 출력
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("T:");
......@@ -94,7 +102,7 @@ void loop() {
lcd.print("Risk: ");
lcd.print(statusText);
// --- Serial 출력 ---
// Serial 출력
Serial.println("=== Sensor Data ===");
Serial.print("Temp: "); Serial.println(temp);
Serial.print("Hum : "); Serial.println(hum);
......@@ -102,6 +110,7 @@ void loop() {
Serial.print("PIR: "); Serial.println(pir);
Serial.print("Hour: "); Serial.println(hour);
Serial.print("Risk: "); Serial.println(statusText);
Serial.print("Riskscore: "); Serial.println(riskScore);
Serial.println("====================\n");
delay(2000);
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment