2021-01-05 00:15:16 -03:00
|
|
|
#include <DHT.h>
|
|
|
|
#define DHTPIN 4 //DHT21
|
|
|
|
#define DHTTYPE DHT21
|
|
|
|
DHT dht21(DHTPIN,DHTTYPE);
|
|
|
|
float temp, hum;
|
|
|
|
|
|
|
|
void setup() {
|
2022-04-04 17:41:38 -04:00
|
|
|
Serial.begin(9600);
|
|
|
|
dht21.begin();
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2022-04-04 17:41:38 -04:00
|
|
|
temp = dht21.readTemperature();
|
|
|
|
hum = dht21.readHumidity();
|
|
|
|
// Comprobación erres de lectura
|
|
|
|
if (isnan(hum) || isnan(temp)) {
|
|
|
|
Serial.println("Error obteniendo los datos del sensor DHT11");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Serial.print("Humedad: ");
|
|
|
|
Serial.print(hum);
|
|
|
|
Serial.println(" %");
|
|
|
|
Serial.print("Temperatura: ");
|
|
|
|
Serial.print(temp);
|
|
|
|
Serial.print(" *C ");
|
|
|
|
delay(2000);
|
|
|
|
}
|