(DHT11)TEMPERATURE AND HUMIDITY GRAPH PLOTTINGWITH THE HELP OF MICROCONTROLLER NODEMCU(HAVING INBUILT WIFI)

In this post, i will try to make you understand the way by which DHT 11 is interfaced with Node MCU(inbuilt ESP8266). 
The 
DHT11 basically is a digital temperature and humidity sensor. It uses a humidity sensor and a thermo resistor to calculate the surrounding air temperature and sends a  digital signal on the digital pin.
NODEMCU
DHT11 sensor


Particulars required. ...........


  • DHT 11 SENSOR 
  • Three male to female jumber cables
  • NODEMCU 
NOW COMING TO THE CONNECTIONS 
WE CONNECT THE GROUND OF THE SENSOR TO THE GND PIN OF THE NODEMCU AND VCC OF THE SENSOR TO THE 3.3V OF THE NODEMCU.AND THE OUTPUT PIN TO ANY OF THE INPUT DIGITAL PINS OF THE  NODEMCU. HERE I HAVE CONNECTED WITH D4.
 And connect the nodemcu to your pc or laptop for uploading the program. 

Now you need to create an account at thingspeak.
And create a new channel at your account and note the write api key to be put in the coding section.
So....now the 
The channel will look like this.
Note the api keys from here.


  1. #include <DHT.h> 
  2. #include <ESP8266WiFi.h> 
  3. String apiKey = "THINGSPEAK API KEY"; // fill your Write API key that is noted 
  4. const char *ssid = "ENTER YOUR SSID"; 
  5. const char *pass = "ENTER YOUR PASSWORD"; 
  6. const char* server = "api.thingspeak.com"; 
  7. #define DHTPIN 2 //pin where the output of dht11 is connected 
  8. DHT dht(DHTPIN, DHT11); 
  9. WiFiClient client; 
  10. void setup() 
  11. Serial.begin(115200) 
  12. delay(120); 
  13. dht.begin(); 
  14. Serial.println("trying to connect to my Wifi"); 
  15. Serial.println(ssid); 
  16. WiFi.begin(ssid, pass); 
  17. while (WiFi.status() != WL_CONNECTED) 
  18. delay(500); 
  19. Serial.print("."); 
  20. Serial.println(""); 
  21. Serial.println("connected to wifi network"); 
  22. void loop() 
  23. float h = dht.readHumidity(); 
  24. float t = dht.readTemperature(); 
  25. if (isnan(h) || isnan(t)) 
  26. Serial.println("unable to read from DHT sensor "); 
  27. return; 
  28. If (client.connect(server, 80)) // 
  29. String postStr = apiKey; 
  30. postStr += "&field1="; 
  31. postStr += String(t); 
  32. postStr += "&field2="; 
  33. postStr += String(h); 
  34. postStr += "\r\n\r\n"; 
  35. client.print("POST /update HTTP/1.1\n"); 
  36. client.print("Host: api.thingspeak.com\n"); 
  37. client.print("Connection: close\n"); 
  38. client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); 
  39. client.print("Content-Type: application/x-www-form-urlencoded\n"); 
  40. client.print("Content-Length: "); 
  41. client.print(postStr.length()); 
  42. client.print("\n\n"); 
  43. client.print(postStr); 
  44. Serial.print("Temperature: "); 
  45. Serial.print(t); 
  46. Serial.print(" degrees Celcius, Humidity: "); 
  47. Serial.print(h); 
  48. Serial.println("%. Going to Thingspeak."); 
  49. client.stop(); 
  50. Serial.println("Waiting..."); 
  51. delay(3000); 
  52. }


Finnaly the plot will look like this


So...now its completed...so thank u guys...byee see you in the next one.
For any doubt type in the comments section. 

Comments

Popular posts from this blog

Blinking led using arduino.

Building a Wifi controlled bot using Nodemcu and l293d motor driver ic

Bascis of Arduino and its description.