I have a code where I am testing for fires. The buzzer is set off if at least one of the fire sensors is LOW (All sensors are set to active-high), based on the output from the OR logic gate. The problem is, the logic gate only outputs a LOW(0) if all sensors are 0. Nothing else. I am not sure why that is and how to fix it.
I am using an Arduino Mega for this.
int buzzer = 2;
int IRSensor1 = 5;
int IRSensor2 = 23;
int IRSensor3 = 24;
int Fire;
void setup() {
Serial.begin(57600);
pinMode(buzzer, OUTPUT);
}
int FlameSensor (int FireSensor){
if (FireSensor == HIGH) {
digitalWrite(buzzer, LOW);
Serial.println("NO FIRE DETECTED");//Serial Monitor
}
else {
digitalWrite(buzzer, HIGH);
Serial.println("FIRE DETECTED");//Serial Monitor
}
}
void loop ( ) {
int FireSensor1 = digitalRead(IRSensor1);
int FireSensor2 = digitalRead(IRSensor2);
int FireSensor3 = digitalRead(IRSensor3);
Serial.print("FireSensor1: ");
Serial.println(FireSensor1);
Serial.print("FireSensor2: ");
Serial.println(FireSensor2);
Serial.print("FireSensor3: ");
Serial.println(FireSensor3);
Fire = FireSensor1 || FireSensor2 || FireSensor3;
Serial.print("Fire: ");
Serial.println(Fire);
FlameSensor (Fire);
delay(1500);
}
