/*
Contoh program LCD 16x2 dengan I2C pada Arduino UNO R3
By     : RAMATECHNO
E-mail : [email protected]
WEB    : https://ramatechno.wordpress.com/
*/

//LCD 16x2 + i2C
#include <LiquidCrystal_I2C.h>

//Atur alamat LCD ke 0x27 atau 0x3F untuk tampilan 16 karakter dan 2 baris
LiquidCrystal_I2C lcd(0x27, 16, 2);

//DHT
#include <DHT.h>
//Konfigurasi Pin DHT
const int dhtPin = 12;
//Konfigurasi Tipe DHT (DHT11)
//#define dhtType DHT11     // DHT 11
#define dhtType DHT22   // DHT 22 (AM2302, AM2321)
//#define dhtType DHT21   // DHT 21 (AM2301)
DHT dht(dhtPin, dhtType);
//Variabel DHT
float h, t, f;

//Custom Icon
//Icon Suhu
byte temperature[8] = {0x04, 0x0A, 0x0A, 0x0E, 0x0E, 0x1F, 0x1F, 0x0E};

//Icon Kelembaban
byte humidity[8] = {0x04, 0x04, 0x0A, 0x0A, 0x11, 0x11, 0x11, 0x0E};

void setup() {
  //LCD 16x2 + i2C
  lcd.init();
  lcd.backlight();
  //DHT Sensor
  dht.begin();
  //Custom Icon
  lcd.createChar(0, temperature); //Suhu
  lcd.createChar(1, humidity);    //Kelembaban
}

void loop() {
  //Tampilan Pada LCD
  lcd.setCursor(0, 0);
  lcd.write((byte)0);
  lcd.print(" : ");
  lcd.print(t);
  lcd.print((char)223); //Simbol derajat
  lcd.print("C  ");
  lcd.setCursor(0, 1);
  lcd.write((byte)1);
  lcd.print(" : ");
  lcd.print(h);
  lcd.print("%   ");
  delay(1000);
  //Baca Kelembaban
  h = dht.readHumidity();
  //Baca temperatur (Celsius)
  t = dht.readTemperature();
  //Baca temperatur (Fahrenheit)
  f = dht.readTemperature(true);
}
NOCOMNCVCCGNDINLED1PWRRelay Module