#include <LiquidCrystal.h>
const byte pinRS = 8;
const byte pinE = 9;
const byte pinDB4 = 10;
const byte pinDB5 = 11;
const byte pinDB6 = 12;
const byte pinDB7 = 13;
const byte pinBttMode = 4;
const byte pinLedGreen = 6;
const byte pinLedRed = 7;
const byte pinGasSensor = 2;
const byte pinTempSensor = 1;
const byte pinLightSensor = 0;
LiquidCrystal lcd(pinRS, pinE, pinDB4, pinDB5, pinDB6, pinDB7);
float stepADC = 0.0048828125;
int gas = 0;
float temp = 0;
int light = 0;
int bttMode = 0;
int gasLimit = 750;
int tempHigh = 40;
int tempLow = 10;
int lightLimit = 350;
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(pinLedGreen, OUTPUT);
pinMode(pinLedRed, OUTPUT);
pinMode(pinBttMode, INPUT);
}
void loop()
{
light = analogRead(pinLightSensor);
temp = (analogRead(pinTempSensor) * stepADC - 0.5) * 100;
gas = analogRead(pinGasSensor);
if ((light > lightLimit) && (temp > tempLow) && (temp < tempHigh) && (gas < gasLimit))
{
digitalWrite(pinLedGreen, HIGH);
digitalWrite(pinLedRed, LOW);
}
else
{
digitalWrite(pinLedGreen, LOW);
digitalWrite(pinLedRed, HIGH);
}
if (digitalRead(pinBttMode) == HIGH)
{
bttMode++;
delay(200);
if (bttMode > 2) bttMode = 0;
}
lcd.clear();
switch (bttMode)
{
case 0:
lcd.print("Light level: ");
lcd.setCursor(2, 1);
lcd.print(light);
break;
case 1:
lcd.print("Temp level: ");
lcd.setCursor(2, 1);
lcd.print(temp);
break;
case 2:
lcd.print("Gas level: ");
lcd.setCursor(2, 1);
lcd.print(gas);
break;
}
Serial.print(gas); Serial.print(" ");
Serial.print(temp); Serial.print(" ");
Serial.print(light); Serial.println("");
delay(500);
}