This sketch prints temperature and humidity in serial monitor OK. I am not sure if I am using the right code to read the outputs of temp/humidity to turn on and off the LED’s. If the temperature falls below 60 degrees turn on ledpin8 and if above 80 degrees turn of ledpin8. Right now my room temp is 77 degrees, when I run the program ledpin8 goes high then low in one click it does not stay high till 80 degrees. Humidity(ledpin9) just goes high then low in less than a second. I just want to turn on ledpin8 when the temperature is below 60 degrees and turn off ledpin8 when the temperature reaches 80 degrees.This is only my second sketch...noobie
Thanks
#include <dht11.h>
dht11 DHT11;
void setup()
{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
const int THRESHOLD3 = 80; // 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;
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
const int THRESHOLD3 = 80; // 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 led...less than 60 degrees
digitalWrite(LEDPIN8, HIGH);
if (DHT11.fahrenheit(), DEC > THRESHOLD3) // temp turn off led.. more than 80 degrees
digitalWrite(LEDPIN8,LOW);
//Humidity
Humidity = (DHT11.humidity, DEC);
if (DHT11.humidity, DEC < THRESHOLD2) // Humidity turn on led than 50 percent
digitalWrite(LEDPIN9, HIGH);
if (DHT11.humidity, DEC > THRESHOLD4) // Humidity turn off led.. more than 75 percent
digitalWrite(LEDPIN9,LOW);
delay(200);
}