• You should set the pin mode in the connect function to pinMode(ht.pin, 'input_pullup');, to avoid random signals to be received.

    And you could replace a code of code as follows, mainly for better comments, from

    ...
      digitalWrite(ht.pin, 0);
      pinMode(ht.pin,"output"); // force pin state to output
      // raise pulse after 1ms
      setTimeout(function() { pinMode(ht.pin, 'input_pullup'); pinMode(ht.pin); }, 20);
      // stop looking after 50ms
    ...
    

    to

    ...
     //pull signal to ground for 20 ms to request data from DHT11
      pinMode(ht.pin,"output");
      digitalWrite(ht.pin, 0);
      setTimeout(function() { pinMode(ht.pin, 'input_pullup'); }, 20);
    
      //parse the received data after 50ms
    ...
    
About

Avatar for maze1980 @maze1980 started