2015年9月18日 星期五

DHT11_LCD2004A_Serial prot

#include  "Wire.h"
#include "LiquidCrystal_I2C.h"
#include "dht.h"

LiquidCrystal_I2C lcd(0x3f,20,4);
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,2);
  lcd.print("Humidity:");
  lcd.setCursor(13,2);
  lcd.print(DHT.humidity, 1);
  lcd.setCursor(18,2);
  lcd.print("%");
  lcd.setCursor(0,3);
  lcd.print("Temperature:");
  lcd.setCursor(13,3);
  lcd.print(DHT.temperature, 1);
  lcd.setCursor(18,3);
  lcd.print("C");

  delay(1000);
}

沒有留言:

張貼留言