Hi Rui
i am doing your dht11 lab. (dht11 and Home automation …ESP8266). Most of the time i get temperature values like 611, 622, etc instead of 22 oder 23 degrees celcius. only sometimes i get the correct values os 22…24 degrees. I have found out that the dht11 is not initialised correcly and the library code thinks there is a dht22 instead – or vice verca, Do you know where to change oder what to cange hange. I using a pulup Resistor and external Power with 5 V for the dht11
Hi Sara, it is the code from your Unit 6 in Home Automation using ESP8266 (below). I also use a external Power 5 v for the DHT11, have a pullUp Resistor of 10 k and the delay between the reads ist 10 sec. I am using the 3pin module with an internal resistor. so i guess i would not need the resistor, but it its the same result without it. I know from raspberry-python code that this mixed results also happens when you access a dht11 as dht22
— Rui Santos
— Complete project details at https://RandomNerdTutorials.com/home-automation-using-esp8266/
wifi.setmode(wifi.STATION)
wifi.sta.config(“#####”,”########”)
tmr.delay(5000)
print(wifi.sta.getip())
pin = 1
bimb = 1
fare = 0
fare_dec = 0
–Read DHT Sensor
function ReadDHT11()
status, temp, humi, temp_dec, humi_dec = dht.read(pin)
if status == dht.OK then
print(string.format(“DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n”,
math.floor(temp),
temp_dec,
math.floor(humi),
humi_dec
))
fare = (9 * math.floor(temp) / 5) + 32
fare_dec = (9 * temp / 5) % 10
elseif status == dht.ERROR_CHECKSUM then
print( “DHT Checksum error.” )
elseif status == dht.ERROR_TIMEOUT then
print( “DHT timed out.” )
end
end
ReadDHT11()
tmr.alarm(1,10000, 1, function() ReadDHT11() bimb=bimb+1 if bimb==5 then bimb=0 wifi.sta.connect() print(“Reconnect”)end end)
srv=net.createServer(net.TCP) srv:listen(80,function(conn)
conn:on(“receive”,function(conn,payload)
–print(payload) — for debugging only
–generates HTML web site
conn:send(‘HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nCache-Control: private, no-store\r\n\r\n\
<!DOCTYPE HTML>\
<html><head><meta charset=”utf-8″><meta name=”viewport” content=”width=device-width, initial-scale=1″></head>\
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>\
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css”>\
<meta http-equiv=”refresh” content=”6″>\
</head><div class=”container”>\
<h1>Sensor Data</h1></br><div class=”row”>\
<div class=”col-md-4″><div class=”panel panel-primary”><div class=”panel-heading”><h3 class=”panel-title”>Humidity</h3>\
</div><div class=”panel-body”>\
<div class=”form-group form-group-lg”><input type=”text” class=”form-control” value=”‘..math.floor(humi)..’.’..humi_dec..’ %”>\
</div></div></div></div>\
<div class=”col-md-4″><div class=”panel panel-info”><div class=”panel-heading”><h3 class=”panel-title”>Temperature</h3>\
</div><div class=”panel-body”>\
<div class=”form-group form-group-lg”><input type=”text” class=”form-control” value=”‘..math.floor(temp)..’.’..temp_dec..’ deg C”>\
<input type=”text” class=”form-control” value=”‘..fare..’.’..fare_dec..’ deg F”>\
</div></div></div></div></div></div></html>’)
conn:on(“sent”,function(conn) conn:close() end)
end)
end)
Hi.
Yes, you’re right. If your DHT sensor only has three pins, you don’t need to add an additional resistor.
You can also power it using 3.3V from the ESP8266 and it should work fine.
As for your problem, it is very difficult to figure out what might be wrong.
Can you try using:
dht.read11() instead of just dht.read() on the ReadDHT11() function and see if that works?
Here you have some documentation about using DHT with LUA firmware: https://nodemcu.readthedocs.io/en/master/modules/dht/
I hope this helps.
Regards,
Sara
Hi
if i use dht.read11() i get a checksum error.
I use also these sensors in an python/raspberry-enviroment. If I run the python-application on raspberry and tell the program to read an dht22, but have a dht11 connected, i get the same results.
So i came to that conclusion: this LUA-Script “thinks” ist has a dht22 connected, but in fact it is a dht11. Where can i tell the programm to use dht11-logic, NOT dht22-code: I guess there might be some code like “if…read dht11, else read dht22” and i think that ist the real issue.