#include<dht11.h>
#include<LiquidCrystal.h>
LiquidCrystal LCD(12,11,2,3,4,5); //宣告一個名為LCD的LiquidCrystal
dht11 DHT; //宣告一個名為DHT的dht11
void setup() {
LCD.begin(16,2); //初始化LCD
}
void loop() {
if(DHT.read(13) == 0) //如果讀取成功輸出溫度和濕度
{
LCD.setCursor(0,0);
LCD.print("Temperature:");
LCD.print((float)DHT.temperature,2);
LCD.print("c");
LCD.setCursor(0,1);
LCD.print("Humidity:");
LCD.print((float)DHT.humidity,2);
LCD.print("%");
}
else{ //讀取失敗則輸出Error
LCD.setCursor(0,0);
LCD.print("Error");
}
delay(2000); //等待兩秒後清除畫面
LCD.clear();
}

Hubert's Coding Notes
Useful notes for CS people