試了半天
原來加個10K電阻就有了
#includedht DHT; #define DHTLIB_OK 0 #define DHTLIB_ERROR_CHECKSUM -1 #define DHTLIB_ERROR_TIMEOUT -2 #define DHTLIB_INVALID_VALUE -999 // the setup function runs once when you press reset or power the board void setup() { Serial.begin(9600); } // the loop function runs over and over again forever void loop() { int chk = DHT.read11(7); switch (chk) { case DHTLIB_OK: Serial.println("OK,\t"); break; case DHTLIB_ERROR_CHECKSUM: Serial.println("Checksum error,\t"); break; case DHTLIB_ERROR_TIMEOUT: Serial.println("Time out error,\t"); break; default: Serial.println("Unknown error,\t"); break; } Serial.println("Humidity = "); Serial.print(DHT.humidity); Serial.print("% "); Serial.print("temperature = "); Serial.print(DHT.temperature); Serial.println("C "); delay(1000); }
程式參考
http://playground.arduino.cc/Main/DHTLib
留言
張貼留言