Temperature and Humidity Sensor interfacing with NodeMCU | DHT11

Sensing Temperature and Humidity using DHT11 sensor module


Temperature and Humidity play a vital role in green houses, home automation, environmental and agricultural data monitoring. We have a low cost and easy to use sensor that can measure temperature and humidity and provide a digital signal output.






As described in above video, lets use one data wire to connect to NodeMCU and measure temperature and humidity. 

Parts Needed

1. NodeMCU / ESP8266
2. Jumper Wires
3. DHT sensor module




Install DHT11 library from Library Manager. (Tools -> Manage Libraries. Search DHT11)


I am installing DHT Sensor library by AdaFruit. Once installed go to File-> Examples -> DHT Sensor Library -> DHTTester

I modified the example to for DHT11. 

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN 2

#define DHTTYPE DHT11   

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }


  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.println(F("°C "));

}

Connections

DHT11 GND - NodeMCU GND
DHT11 Vcc - NodeMCU 3V
DHT Data - D4


Post uploading, open Tools -> Serial Monitor and keep baud rate as 115200.
Now go near the sense and exhale through your mouth, see the changes in humidity
and temperature. Now blow cool air above sensor and see changes to readings.



Troubleshooting
1. DHT11 takes 250ms to sense parameters. Keep a delay of minimum of 2 sec 
between consecutive reading values from sensor.

Comments

Popular posts from this blog

Microphone Sound Sensor explained | HW-484 | Interfacing with ESP 8266

Using ESP 01 in Access Point (AP) mode to control ESP relay switch | ESP wifi tutorial | Part - 1

[Experiment] DIY Robotic 2 wheel drive car using L298N motor driver and NodeMCU | ESP 8266