I have interfaced ESP8266 with DHT11 temperature sensor. The code should ideally print Temperature and Humidity values in serial monitor, but instead its giving the output as given below, and giving nan values for temperature and humidity. Also, this sensor, is perfectly working with Arduino UNO, so no issues with the sensor I believe. Baud rate in code and that of Serial Monitor are both set to 115200.
What could the issue be? Please help. I'm new to this domain, so probably, I might have missed something simple. Please guide me.
Another problem could be: DHT is a 5V sensor, ESP is 3.3V.
Many other, better, temp/humidity sensors are available which are 3.3V devices. BME280 is a good one - it can measure atmospheric pressure as well as temp and humidity. But if temp/humidity is all you need, there is SHT21 for example.
If I were you then I would start by determining that you are addressing the correct pin. Put an LED and resistor (or a DMM set to measure voltage) on pin D8 and run a blink sketch
Connecting the + terminal of the DHT11 to +3.3V is correct. Here is a good description of what each pin is good for:
D8 is pulled down to GND. That could be the problem. Also, if you are using D8 and you place 8 in your code, that will refer to a nonexistent pin as there is no GPIO8 on the ESP8266.
I actually , do not have access to either of those currently, but yes, I was thinking of using a DMM.. I'll try and get one to test, and update here. Thanks a lot in again
Here is the solution: 1. The following setup (Fig-1) does not works; where VCC-pin of the sensor is connected with 3.3V-poin of ESP8266 based NodemCU. It shows: 0 and 0 for Temp and Humidity.
Figure-1:
2. The following setup (Fig-2) works; where the VCC-point of DHT-11 is connected to a seperate 5V supply.
Humidity is = 26
Temperature is = 31
===========================
Humidity is = 26
Temperature is = 31
===========================
Humidity is = 26
Temperature is = 31
===========================
Humidity is = 26
Temperature is = 31
===========================
Thanks a lot everybody. My problem was solved. Turns out, that the sensor had somehow stopped working(It was working previously when I tested it on Arduino). I could fortunately lay hands on another DHT11 sensor, and connected it as per your instructions, its now working perfectly well. Thanks a lot again everyone.