#include <DHTesp.h> //import DHT22 header file
int DHT_PIN = 18; // Assign GPIO 18 to DHT22 sensor
DHTesp dhtSensor;
int LED_PIN = 32;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(DHT_PIN, INPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22); //To declare the sensor will be attached in
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity(); // To get the temperature and humidty sensor model
float tmp = data.temperature;
// put your main code here, to run repeatedly:
Serial.println("Temp: " + String(data.temperature, 2) + "C"); // print the temperature
Serial.println("Humidity " + String(data.humidity, 2) + "%"); // print the humidty
Serial.println("---");
delay(2000); // this speeds up the simulation
if (tmp >= 40) {
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(1000);
}
else {
digitalWrite(LED_PIN, LOW);
}
}