有把DHT.h都下載下來並放到library 裡面了,代碼也是參考網上資源的,
有導通〈但不持續,綠色LED是只閃一下〉,甚至有信號回傳〈黃色LED也是同綠色LED閃一下〉,信號收到卻都是NAN
以下是代碼
#include "DHT.h" // Include the DHT library
#define DHTPIN 13 // Where you have connected you DHT Sensor
#define DHTTYPE DHT11 // Defines the type of the sensor
DHT dht(DHTPIN, DHTTYPE);
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD connection
void setup() {
Serial.begin(115200); // Begins serial communication
Serial.println("Temperature"); // prints the message Temperature on the serial monitor
dht.begin(); // Begins the communications with the temperature sensor
}
void loop() {
float h = dht.readHumidity(); // reads the humidy and stores on the float variable named h
float t = dht.readTemperature(); // reads the temperature and stores on the float variable named t
Serial.print("Humidity: "); // prints the message Humidity: on the serial monitor
Serial.print(h); // prints the humidity value on the serial monitor
Serial.print(" %\t");
Serial.println(); // goes to the next line on the serial monitor
Serial.print("Temperature: "); // prints the message Temperature: on the serial monitor
Serial.print(t); // prints the temperature value on the serial monitor
Serial.print(" *C ");
Serial.println(); // goes to the next line on the serial monitor
if (isnan(h) || isnan(t)) { //This if statement check to see if the DHT sensor is connected or disconnected
Serial.println("Sensor is not connected"); //prints the message sensor is not connected on the serial monitor
}
delay(2000); // wait for two seconds
}