#include "Wire.h"
#include "LiquidCrystal_I2C.h"
#include "dht.h"
LiquidCrystal_I2C lcd(0x27,16,2);
dht DHT;
#define DHT11_PIN 5
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
//lcd.print("DHT11 Test Program ");
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
case DHTLIB_ERROR_CONNECT:
Serial.print("Connect error,\t");
break;
case DHTLIB_ERROR_ACK_L:
Serial.print("Ack Low error,\t");
break;
case DHTLIB_ERROR_ACK_H:
Serial.print("Ack High error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
lcd.setCursor(0,0);
lcd.print("Humidity:");
lcd.setCursor(13,0);
lcd.print(DHT.humidity, 0);
lcd.setCursor(15,0);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("Temperature:");
lcd.setCursor(13,1);
lcd.print(DHT.temperature,0);
lcd.setCursor(15,1);
lcd.print("C");
delay(2000);
}
沒有留言:
張貼留言