#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
// what pin we're connected to
#define DHTPIN 6
// DHT 22 (AM2302)
#define DHTTYPE DHT22
//// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
const int lcdAddress1 = 0x27; // Replace with the actual I2C address of LCD 1
const int lcdAddress2 = 0x28; // Replace with the actual I2C address of LCD 2
const int lcdAddress3 = 0x29; // Replace with the actual I2C address of LCD 3
const int Btn1 = 3;
const int LED = 5;
const int LEDNORMAL = 7;
const int BZR = 4;
volatile bool BUZZER = false;
float h; //Stores humidity value
float t; //Stores temperature value
// I2C address 0x27, 16 column and 2 rows
// I2C LCD displays
LiquidCrystal_I2C lcd1(lcdAddress1, 16, 2);
LiquidCrystal_I2C lcd2(lcdAddress2, 16, 2);
LiquidCrystal_I2C lcd3(lcdAddress3, 16, 2);
void STOPBUZZER() {
BUZZER = true;
}
void setup(void)
{
dht.begin();
Serial.begin(9600);
lcd1.init(); // initialize the lcd
lcd2.init(); // initialize the lcd
lcd3.init(); // initialize the lcd
lcd1.backlight();
lcd2.backlight();
lcd3.backlight();
pinMode(Btn1, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(LEDNORMAL, OUTPUT);
pinMode(BZR, OUTPUT);
attachInterrupt(digitalPinToInterrupt(Btn1), STOPBUZZER, CHANGE);
//detachInterrupt(digitalPinToInterrupt(Btn1));
lcd1.clear(); // clear display
lcd2.clear(); // clear display
lcd3.clear(); // clear display
lcd3.setCursor(3, 0); // move cursor to (0, 0)
lcd3.print("WELCOME TO");
lcd3.setCursor(0, 1);
lcd3.print("SMARTHOME SYSTEM");
delay(500); // display the above for 1 second // display the above for 1 second
}
void loop(void)
{
digitalWrite(LED, LOW);
digitalWrite(BZR, LOW);
t = dht.readTemperature(); // Read temperature
h = dht.readHumidity(); // Read humidity
if (t < 35.00) {
//lcd1.clear(); // clear display
BUZZER = false;
digitalWrite(LEDNORMAL, HIGH);
lcd1.setCursor(0, 0); // move cursor to (0, 0)
lcd1.print(" NORMAL ");
lcd1.setCursor(0, 1);
lcd1.print(" CONDITION ");
delay(500); // display the above for 1 second
//print the temperature in Celsius
Serial.println("NORMAL CONDITION");
}
if (t >= 35.00) {
digitalWrite(LED, HIGH);
digitalWrite(LEDNORMAL, LOW);
if (BUZZER) {
digitalWrite(BZR, LOW);
}
else {
digitalWrite(BZR, HIGH);
}
lcd1.clear(); // clear display
lcd1.setCursor(0, 0); // move cursor to (0, 0)
lcd1.print("TEMP.: ");
lcd1.print(t);
lcd1.print((char)223); //shows degrees character
lcd1.print("C");
lcd1.setCursor(0, 1);
lcd1.print(" WARNING!!! ");
delay(500); // display the above for 1 second
//print the temperature in Celsius
Serial.print("Temperature: ");
Serial.print(t);
Serial.print((char)176);//shows degrees character
Serial.print("C | ");
Serial.println("WARNING");
}
//else {
//lcd1.clear(); // clear display
lcd2.setCursor(0, 0); // move cursor to (0, 0)
lcd2.print("TEMP.: ");
lcd2.print(t);
lcd2.print((char)223); //shows degrees character
lcd2.print("C");
lcd2.setCursor(0, 1);
lcd2.print("HUMI.: ");
lcd2.print(h);
lcd2.print("%");
/*lcd2.print("Fhrt.: ");
lcd2.print((t * 9.0) / 5.0 + 32.0);
lcd2.print((char)223); //shows degrees character
lcd2.print("F"); */
delay(500); // display the above for 1 second
//print the temperature in Celsius
Serial.print("Temperature: ");
Serial.print(t);
Serial.print((char)176);//shows degrees character
Serial.print("C | ");
//print the temperature in Fahrenheit
Serial.print((t * 9.0) / 5.0 + 32.0);
Serial.print((char)176);//shows degrees character
Serial.println("F");
Serial.print("Humidity = ");
Serial.print(h);
Serial.println("% ");
Serial.println("");
//delay(500);
//}
}