|
为什么我的温湿度的值测出来一直显示nan?有大佬可以帮忙解决一下吗?
这是我的代码:
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
//put your setup code here, to run once:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("start");
delay(1000);
dht.begin();
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.println("\n");
lcd.setCursor(0, 0);
lcd.print("Hum:");
lcd.setCursor(7, 0);
lcd.print(h);
lcd.setCursor(11, 0);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.setCursor(7, 1);
lcd.print(t);
lcd.setCursor(11,1);
lcd.print((char)223); //液晶显示“°”
lcd.print("C"); //液晶显示“C”
Serial.print("Humidity: ");//湿度
Serial.println(h);
Serial.print("Temperature: ");//温度
Serial.print(t);
Serial.println(" ℃ ");
delay(2000);
}
|
|