#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);
}
谢谢
答案 0 :(得分:0)
如果您有chk
,它是返回值而不是温度。温度在DHT.temperature
变量中。尝试以下代码:
#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);
}
如果要处理=
温度,还可以将27.00°C
设为1。
答案 1 :(得分:0)
好吧,我找到了解决方案,可能会对某些人有用:
#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);
}