|
本帖最后由 lionelg 于 2012-8-18 13:49 编辑
- #include <LiquidCrystal.h>
- #include <dht11.h>
- dht11 DHT11;
- #define DHT11PIN 3 //DHT11 PIN 3 连接UNO 3
- LiquidCrystal lcd(10,9, 8,7,6,5);
- char hum[10];
- void setup()
- {
-
- // Setup LCD to 16x2 characters
- lcd.begin(16, 2);
- }
- void loop()
- {
- // Display time centered on the upper line
- lcd.setCursor(0,0);
- int chk = DHT11.read(DHT11PIN);
- lcd.clear();
- switch (chk)
- {
- case DHTLIB_OK:
- lcd.print("OK");
- break;
- case DHTLIB_ERROR_CHECKSUM:
- lcd.print("Checksum error");
- break;
- case DHTLIB_ERROR_TIMEOUT:
- lcd.print("Time out error");
- break;
- default:
- lcd.print("Unknown error");
- break;
- }
- lcd.setCursor(0,1);
- lcd.print("%");
- int ih = (int)DHT11.humidity;
- itoa(ih,hum,10);
- lcd.print(hum);
- lcd.setCursor(7,1);
- int lo = DHT11.temperature;
- itoa(lo,hum,10);
- lcd.print(lo);
- delay (1000);
- }
复制代码 根据上面的代码, 温度和湿度显示都是0, 硬件测试过,应该是没问题.有哪位知道是什么情况不?
|
|