`Use code tags to format code for the forum`
/* Temperature humidity sensor */
#include <DHT.h> // Includes the DHT sensor library.
#define datapin 10 // Digital pin connected to
#define DHTTYPE DHT22
DHT dht(datapin, DHTTYPE); // Creates the dht object.
const int Fan = 8;//sets the pin number const int gen_alarm = 9;// sets the pin number
const int LOW_DC_ALARM = 5;//sets the pin number
const int HIGH_DC_ALARM = 4;//sets the pin number
const int CHARG_FAIL_ALARM = 3;//sets the pin number
const int AC_POWER_ALARM = 2;//sets the pin number
int low_dc = 0;//sets state of the switch
int high_dc = 0;//sets state of the switch
int ch_fail = 0;//sets state of the switch
int ac_power = 0;//sets state of the switch dht.begin(); // Initializing the DHT22 sensor module.
pinMode(Fan, OUTPUT);//sets the mode of the pin
digitalWrite(Fan, LOW);//sets the state of the pin
pinMode(gen_alarm, OUTPUT);//sets the mode of the pin
digitalWrite(gen_alarm, LOW);//sets the state of the pin
Serial.begin(9600); // Initialize serial communication
pinMode(LOW_DC_ALARM, INPUT);//sets the mode of the pin
pinMode(HIGH_DC_ALARM , INPUT);//sets the mode of the pin
pinMode(CHARG_FAIL_ALARM, INPUT);//sets the mode of the pin
pinMode(AC_POWER_ALARM, INPUT);//sets the mode of the pin /* Find Temperature & Humidity */
float air_temp = dht.readTemperature();
float humidity = dht.readHumidity();
if(air_temp >= 29,9){
digitalWrite(Fan, HIGH);// the fan switches on
delay(1000);//delay of 1 second
}
if(air_temp <= 26,5){
digitalWrite(Fan, LOW);//It turns the fan off
}
low_dc = digitalRead(LOW_DC_ALARM);// It reads the state of the pin
high_dc = digitalRead(HIGH_DC_ALARM);// It reads the state of the pin
ch_fail = digitalRead(CHARG_FAIL_ALARM);// It reads the state of the pin
ac_power = digitalRead(AC_POWER_ALARM);// It reads the state of the pin
if(low_dc == LOW){
digitalWrite(gen_alarm, HIGH);// HIGH gen_alarm output Pin(switches on the gen_alarm)
lcd.setCursor(11, 2);// Set Cursor position
lcd.print("LOW DC");// print warning message on display
delay(1000);//delay time of 1 second
}else{
delay(1000);//delay time of 1 second
digitalWrite(gen_alarm, LOW);//LOW gen_alarm output Pin(switches off the gen_alarm)
lcd.setCursor(11,2);//set cursor position
lcd.print("No alarm");//print message on the LCD screen
}
if( high_dc == LOW){
digitalWrite(gen_alarm, HIGH);// HIGH gen_alarm output Pin(switches on the gen_alarm)
lcd.setCursor(11, 2);// Set Cursor position
lcd.print("HIGH DC");// print warning message on display
delay(1000);//delay time of 1 second
}else{
delay(1000);//delay time of 1 second
digitalWrite(gen_alarm, LOW);//LOW gen_alarm output Pin(switches off the gen_alarm)
lcd.setCursor(11,2);//set cursor position
lcd.print("No alarm");//print message on the LCD screen
}
if( ch_fail == LOW){
digitalWrite(gen_alarm, HIGH);// HIGH gen_alarm output Pin(switches on the gen_alarm)
lcd.setCursor(11, 2);// Set Cursor position
lcd.print("CH FAIL");// print warning message on display
delay(1000);//delay time of 1 seconds
}else{
delay(1000);//delay time of 1 second
digitalWrite(gen_alarm, LOW);//LOW gen_alarm output Pin(switches off the gen_alarm)
lcd.setCursor(11,2);//set cursor position
lcd.print("No alarm");//print message on the LCD screen
}
if( ac_power == LOW){
digitalWrite(gen_alarm, HIGH);// HIGH gen_alarm output Pin(switches on the gen_alarm)
lcd.setCursor(11, 2);// Set Cursor position
lcd.print("AC POWER");// print warning message on display
delay(1000);//delay time of 1 second
}else{
delay(1000);//delay time of 1 second
lcd.setCursor(11,2);//set cursor position
digitalWrite(gen_alarm, LOW);//LOW gen_alarm output Pin(switches off the gen_alarm)
lcd.print("No alarm");//print message on the LCD screen
}
delay(1000);//delay time of 1 second