DHT11 Humidity Temperature Monitor with NodeMCU on ThingSpeak
This tutorial is all about Humidity & Temperature Monitoring using DHT11 & NodeMCU on ThingSpeak. It explains how to log Humidity & Temperature data on the cloud. We can use Thingspeak as a cloud service provider and DHT11 to measure temperature and humidity.
This tutorial is for NodeMCU on Arduino IDE. You can also configure the ESP8266 board with Arduino to monitor temperature and humidity.
Also check this previous article: Interfacing DHT11 Humdity & Temperature Sensor with Arduino & LCD
Bill of Materials
You just need NodeMCU ESP-12E WiFi Development board and a humidity sensor DHT11 or DHT22. In addition to this breadboard and connecting wires are required.
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | NodeMCU ESP8266 Board | 1 | Amazon | AliExpress |
2 | DHT11 Sensor | 1 | Amazon | AliExpress |
3 | Connecting Wires | 10 | Amazon | AliExpress |
4 | Breadboard | 1 | Amazon | AliExpress |
DHT11 Humidity & Temperature Sensor:
The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed).
It’s fairly simple to use but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using the library, sensor readings can be up to 2 seconds old.
Circuit Diagram & Connection:
Setting Thingspeak & Getting API Key:
1. Go to https://thingspeak.com/ and create an account if you do not have one. Login to your account.
2. Create a new channel by clicking on the button. Enter the basic details of the channel. Then Scroll down and save the channel. You can follow the video guide below.
3. Then go to API keys copy and paste this key to a separate notepad file. You will need it later while programming.
Source Code/Program:
The program for Humidity & Temperature Monitoring using DHT11 & NodeMCU on ThingSpeak is given below.
- Copy this program and paste it on Arduino IDE.
- Download the DHT11/DHT22 library from GitHub and add it to your library manager.
- Select the NodeMCU ESP-12E board from the board manager.
- Paste your API Key from thingspeak which you created earlier on a programming section line.
- Edit the program to change the wifi SSID and password with your own.
- Compile the code and Upload it to NodeMCU board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#include <DHT.h> // Including library for dht #include <ESP8266WiFi.h> String apiKey = "H38TEGNC0XKW43BB"; // Enter your Write API key from ThingSpeak const char *ssid = "how2electronics"; // replace with your wifi ssid and wpa2 key const char *pass = "alhabibi"; const char* server = "api.thingspeak.com"; #define DHTPIN 0 //pin where the dht11 is connected DHT dht(DHTPIN, DHT11); WiFiClient client; void setup() { Serial.begin(115200); delay(10); dht.begin(); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); } void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com { String postStr = apiKey; postStr +="&field1="; postStr += String(t); postStr +="&field2="; postStr += String(h); postStr += "\r\n\r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); Serial.print("Temperature: "); Serial.print(t); Serial.print(" degrees Celcius, Humidity: "); Serial.print(h); Serial.println("%. Send to Thingspeak."); } client.stop(); Serial.println("Waiting..."); // thingspeak needs minimum 15 sec delay between updates delay(1000); } |
34 Comments
Sryy bro….. but it is not compiled at Arduino IDE …it shows
“Multiple libraries were found for “DHT.h”
In file included from E:\Arduino UNO\H_AND_T–DHT11\H_AND_T–DHT11.ino:2:0:
Used: C:\Users\priyansh vashistha\Documents\Arduino\libraries\DHT_sensor_library
C:\Users\priyansh vashistha\Documents\Arduino\libraries\DHT_sensor_library/DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory
Not used: C:\Users\priyansh vashistha\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
#include
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).”
that error ….
Please help me if you can understand this problem and tell me the solution of this problem at my gmail account …
My Email – [email protected]
Delete all other libraries from Arduino library folder and the add the only library that i have given in the link.
Hi sir, is the coding is for dht 11 only? what happen if I use the coding for dht22 sensor?
The same code will work for dht22 also
Will this work if we use a mobile hotspot instead of WiFi..?
Will this work if we use a mobile hotspot instead of WiFi?
will this work,if we use other sensor? like Ac curent and other ? if it can. Can you teach me ?
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new can abort), All SSL ciphers (most compatible), 4MB (FS:none OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”
Build options changed, rebuilding all
In file included from C:\Users\shahid\Documents\Arduino\libraries\DHT_sensor_library\DHT_U.cpp:15:0:
C:\Users\shahid\Documents\Arduino\libraries\DHT_sensor_library\DHT_U.h:36:29: fatal error: Adafruit_Sensor.h: No such file or directory
#include <Adafruit_Sensor.h>
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
We got these errors and we don’t know what to do? Please help us
what is the accuracy ??
Go for SHT31 sensor if you want good accuracy.
Am using dht11 and esp8266 wifi module with your codes unchanged and it will give me how much accuracy level??
Yes
Am using mobile hotspot ..and it is working fine….
Documents\Arduino\libraries\DHT_sensor_library-1.3.8\DHT_U.h:36:29: fatal error: Adafruit_Sensor.h: No such file or directory
#include
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
————————–>>>>>>>>>>>>>>>
—————————>>>>>>>>>>>>>>
I TRIED alot by adding and removing the library but cant solve this issue…,,,,
can u help me??
plse
Documents\Arduino\libraries\DHT_sensor_library-1.3.8\DHT_U.h:36:29: fatal error: Adafruit_Sensor.h: No such file or directory
#include <Adafruit_Sensor.h>
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
————————–>>>>>>>>>>>>>>>
—————————>>>>>>>>>>>>>>
I TRIED alot by adding and removing the library but cant solve this issue…,,,,
can u help me??
plse
what we need to put in server or leave it as it is?
its shows the data is sending to thingspeak but not showing ta thingspeak
Hello How2electronics i m stuck with ”Failed to read from DHT sensor!”
serial monitor allwayws showing and not going further. I m a new one, in programming kindly guide me. regards.
serial.serialutil.SerialException: could not open port ‘COM5’: FileNotFoundError(2, ‘The system cannot find the file specified.’, None, 2)
Hello i have this problem stated above how do i solve this sir?
waiting……………………………………………………………… it can’t be read on thingspeak, please help me… although upload successfully
“Error when configuring the serial port parameters: 250000 N 8 1”
What can this error be? Would you help me? Please!
DTH11 data not getting updated on thinkspeak.com
ONLY QUESTION MARK IS PRINTING PL HELP ME SIR
Hi sir, which DHT library should I used. There are many version of DHT library shared from multiple sources.
Try with anyone, whichever compiles will work for you.
why its not display at website thingspeak??..i use esp32
me too
Which link sir
were u able to do anything about it.?
yes it will work
do it
compilation terminated.
exit status 1
DHT.h: No such file or directory
sir which library should i use for this error
so any luck?
��
���J��H��4�
��
pJ���H�H�&
��
I am resiving this output in serial monitor any idea.
what link?