hello, im quite certain its in the code some where as a I am a beginner to programming . I modified the DHT11 code with some IF statements to trigger relays when the values reach a certain point however they are not working. The rest of the code displays all the information fine.
here is the code . Any help is greatly appreciated! thank you
#include <dht11.h>
dht11 DHT11;
int humid = 3;
int temp = 4 ;
int fan = 5 ;
void setup()
{
DHT11.attach(2);
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
pinMode (humid, OUTPUT);
pinMode (temp,OUTPUT);
pinMode (fan,OUTPUT);
}
void loop()
{
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 (°C): ");
Serial.println((float)DHT11.temperature, DEC);
Serial.print("Temperature (°F): ");
Serial.println(DHT11.fahrenheit(), DEC);
/* Humidity */
if (DHT11.humidity < 70){
digitalWrite (humid, HIGH);
}
else
{
digitalWrite (humid, LOW);
}
/* Temp */
if (DHT11.fahrenheit() < 72) {
digitalWrite (temp, HIGH);
}
else {
digitalWrite (temp,LOW);
}
if (DHT11.fahrenheit() > 76) {
digitalWrite (fan,HIGH);
}
else {
digitalWrite (fan,LOW);
}
delay(2000);
}