int threshold = 25;
#include <DHT.h>
#define DHTPIN 8
#define DATATYPE DHT22
DHT dht(DHTPIN,DATATYPE);
float Celsius = 0;
unsigned long highTime = 0;
unsigned char flagOff = 1;
unsigned char flagTimer = 0;
float prevTemp = 0.0;
void setup() {
// initialize digital pins 12 and 13 as output pins
pinMode(12, OUTPUT);
pinMode(7, OUTPUT);
dht.begin();
}
//12 is red = 12
//13 is yellow =7
void loop() {
float temperature = dht.readTemperature();
if(temperature != prevTemp){
prevTemp = temperature;
flagTimer =0 ;
flagOff = 1;
}
if(temperature >= threshold){
if(flagOff){
digitalWrite(7, HIGH);
digitalWrite(12, LOW);
flagTimer = 1;
highTime = millis();
flagOff = 0;
}
}else {
if(flagOff){
digitalWrite(12, HIGH);
digitalWrite(7, LOW);
flagTimer = 1;
highTime = millis();
flagOff = 0;
}
}
if(flagTimer){
if (millis() - highTime > 180000) {
flagOff = 0;
digitalWrite(12, LOW);
digitalWrite(7, LOW);
flagTimer = 0;
}
}
}
// int threshold = 25;
// #include <DHT.h>
// #define DHTPIN 9
// #define DATATYPE DHT22
// DHT dht(DHTPIN,DATATYPE);
// float Celsius = 0;
// void setup() {
// Serial.begin(9600);
// dht.begin();
// pinMode(12,OUTPUT);
// pinMode(13,OUTPUT);
// pinMode(11,OUTPUT);
// }
// void loop() {
// float t = dht.readTemperature();
// // delayMicroseconds(100);
// if(t<=threshold){
// digitalWrite(12,HIGH);
// digitalWrite(13,LOW);
// }
// else
// {
// digitalWrite(12,LOW);
// digitalWrite(13,HIGH);
// }
// delay(2000);
// digitalWrite(12,LOW);
// digitalWrite(13,LOW);
// }