// https://wokwi.com/projects/348890323831751250
const int buttonPin = 7; // TEST/ALARM
const int noDHT = 6;
const int lowTemp = 5;
const int ledPin = 12; // not using the built in LED
int buttonState = 0;
int tempflag = 0;
int noalarm = 1;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
pinMode(ledPin, OUTPUT);
// I got no hardware, so these simunlate two fault conditions
pinMode(noDHT, INPUT_PULLUP);
pinMode(lowTemp, INPUT_PULLUP);
Serial.begin(9600);
delay(500);
Serial.println(tempflag);
Serial.println(noalarm);
Serial.println("Welcome to the Alert System!");
}
void loop() {
if (noalarm == 0) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
Serial.println("since noalarm == 0");
}
}
if (noalarm == 1) {
Serial.println("Alarm is Not Active. No further action needed");
//digitalWrite(ledPin, HIGH);
delay(2000);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
String PATH_NAME = "*REDACTED*";
Serial.println("Pump alert or test button triggered!");
AlarmOn();
}//END OF ALARM INIT
float f = 47.0 - 4.0 * (digitalRead(lowTemp) ? 0.0 : 1.0);
if (!digitalRead(noDHT)) {
Serial.println(F("Failed to read from DHT sensor!"));
tempflag++;
Serial.println(tempflag);
if (tempflag > 4) {
String PATH_NAME = "*REDACTED*";
Serial.println("DHT sensor failure limit reached!");
AlarmOn();
}
}// END OF TEMP FAIL ALARM
Serial.print("Current Temperature from sensor:");
Serial.print(f);
Serial.print(F("°F"));
Serial. println();
if (45.001 > f) {
String PATH_NAME = "*REDACTED*";
Serial.println("Low Temperature detected!");
AlarmOn();
}// END OF TEMP LOW ALARM
}
}
void AlarmOn() {
//MAKE SURE THAT String PATH is set to the desired email prior to running this function
Serial.println("Starting alarm...");
noalarm = 0;
// connect to web server on port 80:
Serial.println("Connecting...");
Serial.println("connection failed");
Serial.println("Email send failed");
Serial.println("Starting audio and light alarm...");
noalarm = 0;
delay(500);
}