Sonda temperatura y humedad DHT11

Buenos días a todo,
tengo un par de consultas respecto a la sonda de temperatura y humedad DHT11

  1. en la documentación técnica habla de un registro de un byte para la parte entera y otro para la decimal, pero el de la parte decimal siempre está a cero. ¿tiene o no lectuda de decimales

  2. la comunicación en con ceros y unos por un pin del componente, pero en los *.PDE que he encontrado siempre se conecta a un puerto analógico. ¿tiene alguna ventaja?

Un saludo y gracias a todos.

Si puedes poner donde se encuentra dicha documentación, ya que hay varias y no se a cual te refieres.

Ésta es la función que uso, está basada en uno de los tantos códigos que puedes encontrar por internet y si creo recordar bien, recibía decimales.

void readDHT(float pReadings[]){
  byte dht_dat[4], dht_check_sum;

  digitalWrite(DHT11_PIN,LOW);
  delay(18);
  delay(5);
  digitalWrite(DHT11_PIN,HIGH);
  delayMicroseconds(40);
  pinMode(DHT11_PIN,INPUT);
  delayMicroseconds(40);
  if(digitalRead(DHT11_PIN)){
    PgmPrintln("Condicion de inicio 1 no cumplida");
    PgmPrintln("#### EJECUCION DETENIDA ####");
    while(true);
  }
  delayMicroseconds(80);
  if(!digitalRead(DHT11_PIN)){
    PgmPrintln("Condicion de inicio 2 no cumplida");
    PgmPrintln("#### EJECUCION DETENIDA ####");
    while(true);
  }
  delayMicroseconds(80);
  for (byte i=0; i<5; i++) dht_dat[i] = ReadData_DHT();
  pinMode(DHT11_PIN,OUTPUT);
  digitalWrite(DHT11_PIN,HIGH);
  dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];
  if(dht_dat[4] != dht_check_sum) PgmPrintln("Error de checksum");
  pReadings[1] = dht_dat[0]; //Guardamos humedad
  pReadings[0] = dht_dat[2]; //Guardamos temperatura

En cuanto a la pregunta del pin, no debería tener trascendencia alguna, yo lo tenía conectado al pin 32 del mega.

Un saludo

adjunto documento pdf datasheet. En el aparado 5 habla de la parte entera y la parte decimal.
Pero por otros sitios ya he leido que no usa la parte decimal.
¿recomiendas otra sonda de temperatura y humedad algo mejor que esta?

DHT11.pdf (842 KB)

Aqui tienes unos cuantos, aunque son un poco más caros que el DHT11:
http://www.sensirion.com/en/01_humidity_sensors/00_humidity_sensors.htm

he puesto a funcionar la sonda DHT11 en un ambiente industrial y corrompía la parcha del programa principal del arduino. Después de muchos quebraderos de cabeza el problema viene de la función que lee la sonda, que una vez pasado los filtros de tipo fallo 1 y 2 ya asume que va a recibir 40 bits seguidos. Pero si por lo que sea el arduino pierde unos de esos bits, el programa se queda en un bucle while(...) del que nunca sale.
He modificado las funciones que encontré por internet en mi opinión mejorándas.
Los cambios son:

  • el checsum de los 4 bytes lo hace bien (ante siempre daba bien)
  • no se queda tirado por un fallo de comunicación o ruido en el cable de conexión
  • a la función de lectura se le pasan el puerto y la matriz de datos de lectura. De esta forma se puede poner varias sondas en un mismo arduino.
/* variables necesarias para cada sonda DHT11
#define PinSondaDHT 15  // 14 -> analogico 0
byte DatosSondaDHT[3]; // Hr / ºC / error

En setup(){
InitDHT(PinSondaDHT); //preparar sonda para la lectura
delay(1000);// 1000ms recommended delay before accessing sensor

En loop(){
ReadDHT(PinSondaDHT, DatosSondaDHT);

 switch (DatosSondaDHT[2]){
               case 0:
                 .......
                 break;
               case 1:
                 .......
                 break;
               case 2:
                 .......
                 break;
               case 3:
                 .......
                 break;
               default:
                  ......
                  break;
             }
*/
///////////////DEFINICION DE FUNCIONES/////////////////////////////////////////////

void InitDHT(int dht_dpin){
  	pinMode(dht_dpin,OUTPUT);
        digitalWrite(dht_dpin,HIGH);
}
///////////////////////////////////////////////////////////////////////////////////
void ReadDHT(int dht_dpin, byte DatosExt[]){

byte DatosInternos[5];  // %Hr / 0 / ºC / 0 / Sum
DatosExt[2] =0;  // %Hr / ºC / error
//bGlobalErr=0;
byte dht_in;
byte i;  // Send "start read and report" command to sensor...First: pull-down i/o pin for 18ms
digitalWrite(dht_dpin,LOW);
delay(18); //18 mseg tiempo mínimo
delay(5);

digitalWrite(dht_dpin,HIGH);// volver a poner HIGH entre 20-40us
delayMicroseconds(25); //PACO cambio 40 por 25
//Ahora el DT11 se pondrá 80us a LOW y otros 80 us a HIGH
pinMode(dht_dpin,INPUT);
delayMicroseconds(40); // el punto medio de 80
dht_in=digitalRead(dht_dpin);
if(dht_in){
   DatosExt[2] = 1;//ERROR TIPO 1
   return; }

delayMicroseconds(80);
dht_in=digitalRead(dht_dpin);
if(!dht_in){
   DatosExt[2] = 2;// ERROR TIPO 2
   return;}

/*After 80us low, the line should be taken high for 80us by the sensor. The low following that high is the start of the first
  bit of the forty to come. The routine "read_dht_dat()" expects to be called with the system already into this low.*/
delayMicroseconds(60); //PACO cambio 80 por 60 porque ahora los LOW son de 50us y está entre 40 y 40+50=90, por eso 60
//now ready for data reception... pick up the 5 bytes coming from the sensor
for (i=0; i<5; i++)
   DatosInternos[i] = read_dht_dat(dht_dpin);

//Next: restore pin to output duties
pinMode(dht_dpin,OUTPUT); //N.B.: Using DDRC put restrictions on value of dht_pin
digitalWrite(dht_dpin,HIGH);//Next: Make data line high again, as output from Arduino
//N.B.: Using PORTC put restrictions on value of dht_pin

//Next see if data received consistent with checksum received
byte dht_check_sum = DatosInternos[0]+DatosInternos[1]+DatosInternos[2]+DatosInternos[3];
/*Condition in following "if" says "if fifth byte from sensor not the same as the sum of the first four..."*/
if(DatosInternos[4]!= dht_check_sum) {
 DatosExt[2] = 3; //ERROR TIPO 3
 return;}
DatosExt[0] = DatosInternos[0]; // humedad
DatosExt[1] = DatosInternos[2]; // temperatura
}

//////////////////////////////////////////////////////////////////////////////////////////
byte read_dht_dat(int dht_dpin){ //Lee 8 bits de cada vez (0000.0101 is sent, return decimal 5)
  byte i = 0;
  byte result=0;
  for(i=0; i< 8; i++){
      for (int x = 0; x < 200; x ++){
         if (digitalRead(dht_dpin)==HIGH) {break;}}//sale si se pone a uno (max 50uS) o si lleva 200 bucles
         //while(digitalRead(dht_dpin)==LOW); //PACO quito esto // Espera en el LOW de 50uS que hay entre ceros y unos
         //Un cero es un high de 27us y un uno un high de 70uS
      delayMicroseconds(45); //PACO cambio 30 por 45 ( para alejarse más de 27us que es lo que dura un cero)
      // si ahora es HIGH, estamos ante un uno, si el LOW, ya envió un cero
      if (digitalRead(dht_dpin)==HIGH){
            result |=(1<<(7-i));// "add" (not just addition) the 1 to the growing byte
            //ahora esperar a que vuelva a ser cero para leer el siguiente bit
            for (int x = 0; x < 200; x ++){
              if (digitalRead(dht_dpin)==LOW) {break;}}//sale en cuanto se pone a cero (max 70-45 = 25uS)o si lleva 200 bucles
              //while (digitalRead(dht_dpin)==HIGH);//PACO quito esto
      }
  }
  return result;
}