#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 15
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,16,2);
const int gasPin = 33;
void setup() {
lcd.init();
dht.begin();
pinMode(gasPin, INPUT);
lcd.backlight();
lcd.setCursor(2,1); //kolom,baris
lcd.print("hello world");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Tem= ");
lcd.setCursor(10,0); //kolom,baris
lcd.print("Hum= ");
lcd.setCursor(0,1); //kolom,baris
lcd.print("Gas= ");
lcd.setCursor(10,1); //kolom,baris
lcd.print("ppm");
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int gasValue = analogRead(gasPin);
lcd.setCursor(5,0); //kolom,baris
lcd.print(String(temperature, 1));
lcd.setCursor(14,0); //kolom,baris
lcd.print(String(humidity, 1));
lcd.setCursor(5,1); //kolom,baris
lcd.print(String(gasValue));
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
delay(1000);
}