#include "DHT.h"
#include "thingProperties.h"
#define DHT_PIN 23
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define LED_GREEN 32
#define LED_RED 33
#define LED_BLUE 25
const long interval = 2000; //milliseconds
DHT dht(DHT_PIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("DHT22 example!");
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_RED, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
dht.begin();
// Connect to Arduino IoT Cloud
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
readSensorDHT();
delay(interval);
}
void readSensorDHT() {
float humidity, temperature;
humidity = dht.readHumidity(); // Read humidity from sensor
temperature = dht.readTemperature(); // Read temperature from sensor
if (isnan(humidity) || isnan(temperature)) { // Check if any reads failed and exit early (to try again).
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
dht_temperatura = temperature;
dht_humedad = humidity;
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
}
void onLedAzulChange() {
Serial.println("onLedAzulChange triggered");
Serial.println(led_azul);
digitalWrite(LED_BLUE, led_azul ? HIGH : LOW);
}
void onLedRojoChange() {
Serial.println("onLedRojoChange triggered: ");
digitalWrite(LED_RED, led_rojo ? HIGH : LOW);
}
void onLedVerdeChange() {
Serial.println("onLedVerdeChange triggered: ");
digitalWrite(LED_GREEN, led_verde ? HIGH : LOW);
}