INPUT_PULLUP places a ~50K resistor from 5V to the input pin in question.
Note, in this example, we use ALARM
if (flame_value == ALARM || smoke_value == ALARM )
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define ALARM LOW
const byte buzzer = 13; // choose the pin for the Buzzer
const byte flamePin = 10; // choose the input pin (for Fire sensor)
const byte smokePin = 11; // choose the input pin (for smoke sensor)
const byte G_led = 8; // choose the pin for the Green LED
const byte R_led = 9; // choose the pin for the Red Led
byte flame_value; // variable for reading the sensorpin status
byte smoke_value; // variable for reading the sensorpin status
//**************************************************************************************
void setup()
{
pinMode(flamePin, INPUT_PULLUP);
pinMode(smokePin, INPUT_PULLUP);
pinMode(buzzer, OUTPUT); // declare Buzzer as output
pinMode(R_led, OUTPUT); // declare Red LED as output
pinMode(G_led, OUTPUT); // declare Green LED as output
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" WELCOME To ");
lcd.setCursor(0, 1);
lcd.print(" Fire Detector ");
delay(2000);
lcd.clear();
} //END of setup()
//**************************************************************************************
void loop()
{
flame_value = digitalRead(flamePin); // Digital input value
smoke_value = digitalRead(smokePin); //Digital input value
if (flame_value == ALARM || smoke_value == ALARM ) // check if the Fire variable is High
{
lcd.setCursor(0, 0);
lcd.print(" alert ");
lcd.setCursor(0, 1);
lcd.print(" fire ");
digitalWrite(buzzer, HIGH); // Turn LED on.
digitalWrite(R_led, LOW); // Turn LED on.
digitalWrite(G_led, HIGH); // Turn LED off.
delay(100);
}
else // check if the Fire variable is Low
{
lcd.setCursor(0, 0);
lcd.print("...CONDITIONS...");
lcd.setCursor(0, 1);
lcd.print(".....Normal.....");
digitalWrite(buzzer, LOW); // Turn LED off.
digitalWrite(R_led, HIGH); // Turn LED off.
digitalWrite(G_led, LOW); // Turn LED on.
}
delay(100);
} //END of loop()