const float BETA = 3950;
int sensor1counter = 0;
int sensor2counter = 0;
const int relay = 10;
int suspendbuzzer = 0;
int suspendbutton = 0; // determine if a suspend button is pressed
// user defined parameters
const int sensor1_possitive_max = 5;
const int sensor2_possitive_max = 5;
const int time_to_turn_off_pump = -14;
const int alarm_suspend_time = 6;
void setup() {
pinMode(11, INPUT_PULLUP );
pinMode(10, OUTPUT);
Serial.begin(9600);
digitalWrite(2, LOW); // sensor 1 ready
digitalWrite(3, LOW); // sensor 1 triggered
digitalWrite(relay, LOW); // relay
// display user parameters and wait 5 seconds before this shit will go on
Serial.println("Declared Parameters / Variables: ");
Serial.print("Sensor 1 threshold: "); Serial.println(sensor1_possitive_max);
Serial.print("Sensor 2 threshold: "); Serial.println(sensor2_possitive_max);
Serial.print("Alarm snooze [s]: "); Serial.println(alarm_suspend_time);
Serial.print("Time to shut down the pump [s]: "); Serial.println(time_to_turn_off_pump);
Serial.println("...monitoring will start in 5 secs...");
delay (5000);
}
void loop() {
//first sensor reading and calculation
int sensor1_analogValue = analogRead(A2);
float sensor1_value = 1 / (log(1 / (1023. / sensor1_analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// second senor reading and calculation
int sensor2_analogValue = analogRead(A3);
float sensor2_value = 1 / (log(1 / (1023. / sensor2_analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: "); Serial.print(sensor1_value); Serial.println(" ℃");
Serial.print("Temperature: "); Serial.print(sensor2_value); Serial.println(" ℃");
Serial.print("Sensor 1 counter: "); Serial.println(sensor1counter);
Serial.print("Sensor 2 counter: "); Serial.println(sensor2counter);
Serial.print("suspendbutton: "); Serial.println(suspendbutton);
Serial.print("suspendbuzzer: "); Serial.println(suspendbuzzer);
Serial.println("----------");
// sensor 1 triggered
if(sensor1_value>50){
sensor1counter = sensor1counter+1 ;
}
else {
if (sensor1counter == 0) {}
else{
sensor1counter = sensor1counter-1;
}
}
if (sensor1counter >= sensor1_possitive_max) {
digitalWrite(3, HIGH);
if (suspendbuzzer <=0) {tone(12, 262, 125);}
suspendbutton = digitalRead(11);
if (suspendbutton == HIGH){
suspendbuzzer = alarm_suspend_time;}
suspendbuzzer = suspendbuzzer-1;
if (suspendbuzzer>0) {digitalWrite(3, LOW);}
}
// sensor 2 triggered
if(sensor2_value>50){
sensor2counter = sensor2counter+1 ;
}
else {
if (sensor2counter == 0) {}
else{
sensor2counter = sensor2counter-1;
}
}
if (sensor2counter >= sensor2_possitive_max) {
digitalWrite(4, HIGH);
if (suspendbuzzer <=0) {tone(12, 262, 125);}
suspendbutton = digitalRead(11);
if (suspendbutton == HIGH){
suspendbuzzer = alarm_suspend_time;}
suspendbuzzer = suspendbuzzer-1;
if (suspendbuzzer>0) {digitalWrite(4, LOW);}}
// prepare pump or relay to stop
if (suspendbuzzer < time_to_turn_off_pump) {
digitalWrite(relay, HIGH);
Serial.println("the Fuel Pump Has Been Stopped");
delay (100000);
}
delay(1000);
}