0
votes

i not have much experience with arduino and need your help . i need switch on / of build in led then temperature rich 27 C . I write scratch but its not work , its read temperature and humidity but led not work , please you help , where is mistake ?

#include <dht.h>

dht DHT;

#define DHT11_PIN 2

void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
float chk = DHT.read11(DHT11_PIN);
if ( chk > 27.00 )
   digitalWrite( LED_BUILTIN, HIGH);
if ( chk < 27.00 )
   digitalWrite( LED_BUILTIN, LOW);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(2000);
}

Thank you

2

2 Answers

0
votes

In if you have chk which is return value and not temperature. Temperature is in DHT.temperature variable. Try this code:

#include <dht.h>

dht DHT;

#define DHT11_PIN 2

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  if ( DHT.temperature > 27.00 )
    digitalWrite( LED_BUILTIN, HIGH);
  if ( DHT.temperature <= 27.00 )
    digitalWrite( LED_BUILTIN, LOW);

  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(2000);
}

Also put = to one if to handle 27.00°C temperature.

0
votes

Ok i find the solution , may be its will useful for some one :

#include <dht.h>

dht DHT;

#define DHT11_PIN 2

void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  if ( DHT.temperature > 27.00 )
     digitalWrite( LED_BUILTIN, HIGH);
  if ( DHT.temperature < 27.00 )
     digitalWrite( LED_BUILTIN, LOW);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(2000);

}