Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By pstryk
#56497 Hi,

I am having a problem with my dht22 sensor and nodemcu.

I am getting timeout errors all the time.

Here is my Lua:

Code: Select allfunction get_data_from_dht()
        dht=require("dht")
        status,temp,humi,temp_decimial,humi_decimial = dht.read(2)
        if( status == dht.OK ) then
            -- Prevent "0.-2 deg C" or "-2.-6"
            temperature = temp.."."..(math.abs(temp_decimial)/100)
            humidity = humi.."."..(math.abs(humi_decimial)/100)
            -- If temp is zero and temp_decimal is negative, then add
            -- "-" to the temperature string
            if(temp == 0 and temp_decimial<0) then
                temperature = "-"..temperature
            end
            print("Temperature: "..temperature.." deg C")
            print("Humidity: "..humidity.."%")
        elseif( status == dht.ERROR_CHECKSUM ) then
            print( "DHT Checksum error" )
            temperature=-1 --TEST
        elseif( status == dht.ERROR_TIMEOUT ) then
            print( "DHT Time out" )
            temperature=-2 --TEST
        end
    -- Release module
    dht=nil
    package.loaded["dht"]=nil
end

get_data_from_dht()


Pins are:
+ to 3v3
- to GND
out to D2

Any help would be apppreciated.
User avatar
By Terraformer
#57404 Hi,

Maybe it's not a software but hardware problem? I've found the DHT22 to be pretty picky when using ESP01 and ESP12F--or other µC ;). Did you try the DHT22 with a different µC? Any capacitors added to the DHT and what pull-up did you choose? How long are the wires?

Best!