2018年5月22日 星期二

DHT11 Temperature & Humidity sensor on NodeMCU using Arduino IDE


DHT11 Temperature & Humidity sensor on NodeMCU using Arduino IDE

Robo India presents tutorial on how to read temperature and humidity data through DHT11 sensor using ESP8266 wifi module on NODEMCU LUA platform.

Detailed Tutorial
1. Introduction:
The DHT11 is chosen because it is lab calibrated, accurate and stable and its signal output is digital. Most important of all, it is relatively inexpensive for the given performance. Below is the pinout of the sensor.
2. Understanding DHT11 sensor
DHT11 sensor gives humidity and temperature data. It has got following pin interface.
DHT11-Pinout_
3. Circuit
Make the following connections -
DH11-with-amica_
4. Library File
Following two libraries will be required to run this code. Download the zip file extract the same and copy this to your Arduino library folder.
This library file should be placed at the install folder of Arduino. I have a 64 bit Win7 OS and my arduino library folder address is located at
C:\Program Files (x86)\Arduino\libraries 
5. Programming
#include "DHT.h"        // including the library of DHT11 temperature and humidity sensor
#define DHTTYPE DHT11   // DHT 11

#define dht_dpin 0
DHT dht(dht_dpin, DHTTYPE); 
void setup(void)
{ 
  dht.begin();
  Serial.begin(9600);
  Serial.println("Humidity and temperature\n\n");
  delay(700);

}
void loop() {
    float h = dht.readHumidity();
    float t = dht.readTemperature();         
    Serial.print("Current humidity = ");
    Serial.print(h);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(t); 
    Serial.println("C  ");
  delay(800);
}

6. Output
Upload the above code to the NodeMCU and open serial monitor. Following output should be shown on the serial monitor.
Output
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...