#include <DHTesp.h> //Import DHT22 header file
int DHT_PIN = 18; // Assign GPIO 18 to DH22
int LED_PIN = 25; // Assign
DHTesp dhtSensor; // Create an instance from DHTesp library
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(DHT_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22); //To declare the sensor will be attached in with pin and sensor model
}
void loop()
{
// put your main code here, to run repeatedly:
TempAndHumidity data = dhtSensor.getTempAndHumidity(); // To get the temperature humidity from the sensor
float tmp = data.temperature;
Serial.println("Temp: " + String(data.temperature, 2) + "*C"); // Print the temperature
Serial.println("Humidity: " + String(data.humidity, 2) + "%"); // Print the humidity
Serial.println("---");
if (tmp >= 40)
{
digitalWrite(LED_PIN, HIGH);
delay(1000);
}
else
{
digitalWrite(LED_PIN, LOW);
}
delay(2000); // Whait for a new reading of the sensor
}