NodeMCU ESP8266 Devkit ESP12 with DHT11

This post is to understand the DHT11 sensor working  with Node MCU board. It will also help to understand the pseudo code  required. I am using DHT11 mounted in Blynk board. The video to explain this is available  here.

Please SUBSCRIBE to YouTube channel Embedkari  for further discussion on Embedded Systems. 

Setup Requirements

1: ESP8266 Node MCU board

2: Blynk Board for IoT

I have also provided link to purchase both the boards.

What is NodeMCU ?

Here  is overview about NodeMCU (Node MicroController Unit).

The NodeMCU  is an open source software and hardware development environment that is built around a very inexpensive System-on-a-Chip (SoC) called the ESP8266. The ESP8266, designed and manufactured by Espressif Systems, contains all crucial elements of the modern computer: CPU, RAM, networking (wifi), and even a modern operating system and SDK.

NodeMCU is an open source Lua based firmware for the ESP8266 WiFi SOC from Espressif and uses an on-module flash-based SPIFFS file system. NodeMCU is implemented in C and is layered on the Espressif NON-OS SDK.

What is DHT11 ?

DHT11 is a low cost humidity and temperature sensor which generates calibrated digital output. This sensor includes a resistive-type humidity measurement component and an NTC (Negative Temperature Coefficient) temperature measurement component, Most humidity sensors use capacitive measurement to determine the amount of moisture in the air.

One should check all the parameters such as operating temperature range,voltage,current,accuracy ,resolution etc from the datasheet of DHT11 device. I lhave provided datasheet of one particular device as reference. It provides relative humidity (RH) of accuracy +/- 5% and temperature measurement of accuracy +/-2 degree Centigrade.

I opened one faulty DHT11 sensor for inspection.

Connection Diagram is very simple. Only three connections are required to be made to use the sensor – Vcc, Gnd and Output.Pin 3 of DHT11 is NC(Not Connected) . Pin2 provides the digital output.

Since I am using DHT11 mounted in Blynk board, I have to only plug-in the Node MCU board to Blynk board and connect USB cable to PC where Arduino IDE is installed

How data transmission starts ?

MCU sends a start signal to start communication. This wakes up the sensor from sleep mode and  sensor sends a response  followed by a burst of 40 bits data .

How data 0 is encoded?

How data 1 is encoded ?

You may notice the bit is high for longer duration in case of data 0. This can be found in device data sheet.

Frame transmission :

The data format consists of five bytes(40 bits) as follows

 integral  RH decimal RH integral T decimal T  check sum

Pseudo code:

  • Send Start pulse
    • PinMode=output
    • PinData=0
    • Delay for Low duration
    • PinMode=input
    • delay for 40 microsec
  • Wait for ACK Low duration
  • Wait for ACK High duration
  • Read 40 bits in buffer with monitoring the timeout for data 0 or data 1.
  • Check the data received with checksum
  • Check status flag ,data buffer and act accordingly

Reference :

DHT11 data sheet 

NodeMCU Doc 

Please SUBSCRIBE to YouTube channel Embedkari  for additional embedded related stuff.



Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.