วันพฤหัสบดีที่ 21 ธันวาคม พ.ศ. 2560

DHT11+LCD+Arduino UNO



Link for download LCD library https://www.dropbox.com/s/1aahz8f5pn5...




Code


#include "DHT.h"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

DHT dht;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");

  dht.setup(2); // data pin 2

  // initialize the LCD
  lcd.init();
  lcd.backlight();
  lcd.print("Sensor Family");
        lcd.setCursor(0, 1);
        lcd.print("A-Arduino Thailand");
}

void loop()
{
  delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();

  Serial.print(dht.getStatusString());
  Serial.print("\t");
  Serial.print(humidity, 1);
  Serial.print("\t\t");
  Serial.print(temperature, 1);
  Serial.print("\t\t");
  Serial.println(dht.toFahrenheit(temperature), 1);

  delay(1000);


  // initialize the LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Humi");
  lcd.setCursor(8,0);
  lcd.print(humidity);

  lcd.setCursor(0,1);
  lcd.print("Temp");
  lcd.setCursor(8,1);
  lcd.print(temperature);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น