Skip to content

Instantly share code, notes, and snippets.

@ceiborg
Created September 17, 2019 17:48
Show Gist options
  • Select an option

  • Save ceiborg/6fa2676554586d25d05e30249b34f67d to your computer and use it in GitHub Desktop.

Select an option

Save ceiborg/6fa2676554586d25d05e30249b34f67d to your computer and use it in GitHub Desktop.
Modulo sensor de Temperatura y Humedad Dht11
/*
#############%@
#### #########%
## #########&
#% ##########
### ############
################### ceiborg.com
################### tecnotextiles
##################
#################
##############
##
#
*/
//Modulo sensor de Temperatura y Humedad Dht11
// Incluimos librería
#include <DHT.h>
// Definimos el pin digital donde se conecta el sensor
#define DHTPIN 2
// Dependiendo del tipo de sensor
#define DHTTYPE DHT11
// Inicializamos el sensor DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Inicializamos comunicación serie
Serial.begin(9600);
// Comenzamos el sensor DHT
dht.begin();
}
void loop() {
// Esperamos 5 segundos entre medidas
delay(5000);
// Leemos la humedad relativa
float h = dht.readHumidity();
// Leemos la temperatura en grados centígrados (por defecto)
float t = dht.readTemperature();
// Comprobamos si ha habido algún error en la lectura
if (isnan(h) || isnan(t)) {
Serial.println("Error obteniendo los datos del sensor DHT11");
return;
}
// Calcular el índice de calor en grados centígrados
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humedad: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print("Sensacion Termica: ");
Serial.print(hic);
Serial.println(" *C ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment