#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
int pinPIR = 15;
DHT dht(DHTPIN, DHTTYPE);
boolean statusIR = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(pinPIR, INPUT);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float hic = dht.computeHeatIndex(t, h, false);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
statusIR = digitalRead(pinPIR);
if (statusIR) {
Serial.println("Ada orang");
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print("\n");
Serial.print("\n");
} else {
Serial.println("Tidak ada orang");
}
// put your main code here, to run repeatedly:
delay(1000); // this speeds up the simulation
}