Sunteți pe pagina 1din 7

C Source Code

#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#include<Keypad.h>
#include "MQ7.h"
#include <MQ2.h>
#define DHTPIN1 41
#define DHTPIN2 37
#define DHTPIN3 39
#define FLAME 14
#define DHTTYPE DHT22
MQ7 mq7(A2 ,5.0);
int LPGpin = A1;
MQ2 mq2(LPGpin);
DHT dht(DHTPIN1, DHTTYPE);
DHT dht1(DHTPIN2, DHTTYPE);
DHT dht2(DHTPIN3, DHTTYPE);
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const byte ROWS = 4;
const byte COLS = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {23, 25, 27, 29};
byte colPins[COLS] = {31, 33, 35};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int lpg;
int ppm;
int chk;
float hum;
float temp;
float temp1;
int a;
int b;
int value=0;
char customKey;
long second = 0;
int tempCus;
bool l = true;
bool ppmbool = true;
bool lpgbool = true;
bool tempbool = true;
bool pinNine = true;
int LPGA0 = A1;
float temp2;
float temp3;
float temp4;
int manualPin=53;
void setup() {
lcd.begin(16, 4);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(FLAME, INPUT);
pinMode(manualPin,INPUT);
Serial.begin(9600);
pinMode(LPGA0, INPUT);
dht.begin();
dht1.begin();
dht2.begin();
}
void loop() {
int fire = digitalRead(FLAME);
if(manualPin != LOW){
second = 0;
lcd.setCursor(0, 1);
if(l == true){
lcd.print("Enter Temp Press * or #");
tempCus = SecondNumber();
lcd.clear();
lcd.print(tempCus);
delay(1000);
lcd.clear();
l = false;
}
ppm = mq7.getPPM();
float* values= mq2.read(true);
lpg= analogRead(LPGA0);
fire = digitalRead(FLAME);
temp2= dht.readTemperature();
temp3 = dht1.readTemperature();
temp4= dht2.readTemperature();
temp= (temp2+temp3+temp4)/3;
lcd.setCursor(0, 0);
lcd.print("Temp 1: ");
lcd.print(temp2);
lcd.setCursor(0, 1);
lcd.print("Temp 2: ");
lcd.print(temp3);
lcd.setCursor(0, 2);
lcd.print("Temp 3: ");
lcd.print(temp4);
lcd.setCursor(0, 3);
lcd.print("Temp Avg: ");
lcd.print(temp);
delay(3000);
Serial.print("Temp 1: ");
Serial.println(temp2);
Serial.print("Temp 2: ");
Serial.println(temp3);
Serial.print("Temp 3: ");
Serial.println(temp4);
Serial.print("Temp Avg: ");
Serial.println(temp);
lcd.clear();
a = tempCus-0;
b = tempCus+0;
lpg= analogRead(LPGA0);
ppm = mq7.getPPM();
temp2= dht.readTemperature();
temp3 = dht1.readTemperature();
temp4= dht2.readTemperature();
temp= (temp2+temp3+temp4)/3;
Serial.print("PPM: ");
Serial.println(ppm);
Serial.print("Temp: ");
Serial.println(temp);
Serial.print("Lpg: ");
Serial.println(lpg);
Serial.print("Temp Custom: ");
Serial.println(tempCus);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("AVG TEMP: ");
lcd.print(temp);
lcd.setCursor(0,1);
lcd.print("CO: ");
lcd.print(ppm);
lcd.setCursor(0,2);
lcd.print("LPG: ");
lcd.print(lpg);
lcd.setCursor(0,3);
lcd.print("User Temp: ");
lcd.print(tempCus);
delay(3000);
Serial.print("Start");
if(ppm <= 70){
ppmbool = true;
digitalWrite(6,LOW);
if(lpgbool == true && tempbool == true){
if(lpg > 200 && temp < b){
if(pinNine == true){
digitalWrite(9,HIGH); delay(1000);
digitalWrite(8,HIGH);
delay(5000);
digitalWrite(8,LOW);
pinNine = false;
fire = digitalRead(FLAME);}
else{
ppmbool = false;
digitalWrite(9,LOW);
delay(1000);
digitalWrite(6,HIGH);
pinNine = true;
delay(1000);
digitalWrite(9,LOW);
}
lcd.clear();
delay(1000);
lcd.setCursor(0, 2);
//temp1= dht.readTemperature();
lcd.setCursor(0, 1);
lcd.clear();
lpg= analogRead(LPGA0);
ppm = mq7.getPPM();
temp2= dht.readTemperature();
temp3 = dht1.readTemperature();
temp4= dht2.readTemperature();
temp= (temp2+temp3+temp4)/3;
if(lpg < 200){
digitalWrite(9,LOW);
lpgbool = false;
Serial.print("LPG");
}else if(temp > b){
digitalWrite(9,LOW);
tempbool = false;
Serial.print("TEmpraute");
}
if(lpgbool == false){
lpg= analogRead(LPGA0);
if(lpg > 200 && ppmbool == true){
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(8,HIGH);//For tik tik
delay(5000);
digitalWrite(8,LOW);
lpgbool = true;
}
else if(tempbool == false){
temp2= dht.readTemperature();
temp3 = dht1.readTemperature();
temp4= dht2.readTemperature();
temp= (temp2+temp3+temp4)/3;
if(temp < b && ppmbool == true){
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(8,HIGH);//For tik tik
delay(5000);
digitalWrite(8,LOW);
tempbool = true;
}
}
Serial.print(fire);
digitalWrite(9,LOW);
delay(2000);
lpg= analogRead(LPGA0);
delay(30000);//fire k bad
if(lpg > 200){
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(8,HIGH);//For tik tik
delay(5000);
digitalWrite(8,LOW);
pinNine = false;
break;
}
}
}else{
lcd.setCursor(0,0);
lcd.print("System on manual");
delay(2000);
if(pinNine == true){
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(8,HIGH);//For tik tik
delay(5000);
digitalWrite(8,LOW);
delay(1000);
pinNine = false;
}
while(digitalRead(FLAME) == LOW){
digitalWrite(9,LOW);
delay(5000);
lpg= analogRead(LPGA0);
if(lpg > 200){
pinNine = true;
break;
}
long SecondNumber()
{
while( 1 )
{customKey = keypad.getKey();
if(customKey >= '0' && customKey <= '9')
{ second = second * 10 + (customKey - '0'); }
if(customKey == '*' || customKey=='#'){
break; //return second; }
return second; }

S-ar putea să vă placă și