Hi guys finally i got the sketch running perfectly but still i am not very clear about what was the problems with the previous sketches. any way thanking every body for giving valuable comments over my project. Thanks a lot.
my new sketch is
#include <dht.h>
dht DHT;
#define DHT1_PIN 7 // dht11 connected to pin 7
int exhaustpin = 4; // set pin for exhaust fan relay
int coolerpin = 5; // set pin for cooler relay
boolean exhaustState;
boolean coolerState;
boolean startTimer;
unsigned long countDown;
unsigned long currentmillies;
void setup() {
Serial.begin(9600);
pinMode(exhaustpin, OUTPUT);
pinMode(coolerpin, OUTPUT);
digitalWrite(exhaustpin, HIGH );
digitalWrite(coolerpin, HIGH );
boolean exhaustState = HIGH;
boolean coolerState = HIGH;
unsigned long countDown = 0;
}
void loop()
{
DHT.read11(DHT1_PIN);
Serial.print(" MY Room Temperature = ");
Serial.println(DHT.temperature);
Serial.print("MY Room Humidity = ");
Serial.println(DHT.humidity);
delay(500);
int roomtemp = DHT.temperature;
if ((roomtemp >= 30) && (coolerState == HIGH)) { // Turn on the exhaust fan if the teperature is more than or equal to 30 degree
digitalWrite(exhaustpin, LOW );
exhaustState = LOW;
}
if ((exhaustState == LOW) && (countDown == 0)) {
startTimer = HIGH; // starts the countdown after turning on the exhaust fan
countDown = millis();
}
if (startTimer == HIGH) {
{
currentmillies = millis();
}
if ( currentmillies - countDown >= 600000) { // after 10 minutes past if the temperature is still greater than 28 degrees the exhaust fan Off and cooler ON
digitalWrite(coolerpin, LOW );
coolerState = LOW;
digitalWrite(exhaustpin, HIGH );
exhaustState = HIGH;
startTimer = LOW; // countdown stops
}
}
if (roomtemp < 28) { // if the temperature is less than 28 degress both the exhaust and cooler turn 0FF.
digitalWrite(coolerpin, HIGH );
digitalWrite(exhaustpin, HIGH );
exhaustState = HIGH;
coolerState = HIGH;
countDown = 0; // Resets the count down value to Zero
}
}