When I set the (temp) threshold1 to 60 ( lower limit), which is below my room temp and threshold3 to 80(upper limit), Ledpin8 just flashes once and goes low, never comes on again, unless restart. I wonder if my IF statements are right? At least a LED comes on. The prog prints temp/humidity OK
#include <dht11.h>
dht11 DHT11;
void setup()
{
DHT11.attach(2);
Serial.begin(9600);
}
void loop()
{ const int LEDPIN8 = 8; // Temp
const int LEDPIN9 = 9; // Humidity
pinMode (LEDPIN8, OUTPUT); // Temp
pinMode (LEDPIN9, OUTPUT); // Humidity
const int THRESHOLD1 = 60; // Temp lower limit turn on..60
const int THRESHOLD3 = 100; // Temp upper limit turn off
const int THRESHOLD2 = 50; // humidity lower limit turn on
const int THRESHOLD4 = 75; // humidity upper limit turn off
float Temperature;
float Humidity;
Serial.println("\n");
int chk = DHT11.read();
Serial.print("Read sensor: ");
switch (chk)
{
case 0:
Serial.println("OK");
break;
case -1:
Serial.println("Checksum error");
break;
case -2:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, DEC);
Serial.print("Temperature (F): ");
Serial.println(DHT11.fahrenheit(), DEC);
//Temperature
Temperature = (DHT11.fahrenheit(), DEC);
if (DHT11.fahrenheit(), DEC < THRESHOLD1) // temp turn on...less than 60
digitalWrite(LEDPIN8, HIGH);
//delay(4000);//works on temp
if (DHT11.fahrenheit(), DEC > THRESHOLD3) // temp turn off.. more than 80
digitalWrite(LEDPIN8,LOW);
//Humidity
Humidity = (DHT11.humidity, DEC);
if (DHT11.humidity, DEC < THRESHOLD2) // Humidity turn on les than 50
digitalWrite(LEDPIN9, HIGH);
//delay(2000);//no work on hum
if (DHT11.humidity, DEC > THRESHOLD4) // Humidity turn off.. more than 75
digitalWrite(LEDPIN9,LOW);
delay(200);
}
Moderator edit: CODE TAGS