#include "DHTesp.h" //agregamos la libreria para manejar el sensor
const int DHT_PIN=19; //declaramos el GPIO19 para la lectura
const int LED_TEMP=14; //declaramos el GPIO14 para la escritura del led
const int LED_HUM=15;
const int ACT_TEMP=26;
const int ACT_HUM=27;
bool boton_temp=false;
bool boton_hum=false;
DHTesp dhtSensor;
const float umbralTemp = 45.0;
const float umbralHum1 = 25.0;
const float umbralHum2 = 60.0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(26,INPUT);
pinMode(27,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
boton_temp=digitalRead(ACT_TEMP);
if(boton_temp == HIGH)
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
delay(1000); // this speeds up the simulation
Serial.println("Temp: " + String(data.temperature, 1) + "°C");
if (data.temperature > umbralTemp)
{
Serial.println("Umbral de temperatura superado");
digitalWrite(LED_TEMP,HIGH);
}
else
{
digitalWrite(LED_TEMP,LOW);
}
}
boton_hum=digitalRead(ACT_HUM);
if(boton_hum == HIGH)
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
delay(1000); // this speeds up the simulation
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
if (data.humidity > umbralHum2 || data.humidity < umbralHum1)
{
Serial.println("Umbral de humedad superado");
digitalWrite(LED_HUM,HIGH);
}
else
{
digitalWrite(LED_HUM,LOW);
}
}
if(boton_temp==LOW && boton_hum==LOW)
{
Serial.println("Por favor active alguno de los controladores");
digitalWrite(LED_TEMP,LOW);
digitalWrite(LED_HUM,LOW);
}
delay(1000); // this speeds up the simulation
}