DHT Temperature and Humidity Monitoring Using the ESP8266 and the AskSensors IoT Platform




Introduction: DHT Temperature and Humidity Monitoring Using the ESP8266 and the AskSensors IoT Platform

About: IoT Maker, co-founder of asksensors.com

In a previous instructable, I presented a step by step guide to get started with the ESP8266 nodeMCU and the AskSensors IoT platform.

In this tutorial, I'm connecting a DHT11 sensor to the node MCU. The DHT11 is a commonly used Temperature and humidity sensor for prototypes monitoring the ambient temperature and humidity of a given area.

The sensor can measure temperature from 0°C to 50°C with an accuracy of ±2°C and humidity from 20% to 90% with an accuracy of ±5% RH.

DHT11 Specifications:

  • Operating Voltage: 3.5V to 5.5V
  • Operating current: 0.3mA (measuring) 60uA (standby)
  • Output: Serial data
  • Temperature Range: 0°C to 50°C
  • Humidity Range: 20% to 90%
  • Resolution: Temperature and Humidity both are 16-bit
  • Accuracy: ±2°C and ±5%

Step 1: Bill of Material

The material required is composed from:

  1. ESP8266 nodeMCU, but feel free to use different ESP8266 compatible modules.
  2. DHT11 sensor, The DHT22 is also an alternative.
  3. USB Micro cable to connect the nodeMCU to your computer.
  4. Wires for connections between the DHT11 and the nodeMCU.

Step 2: Pinout and Connections

You may find the DHT11 sensor in two different pinout configurations:

DHT sensor with 3 pins:

  1. Power supply 3.5V to 5.5V
  2. Data, Outputs both Temperature and Humidity through serial Data
  3. Ground, Connected to the ground of the circuit

DHT sensor with 4 pins:

  1. Power supply 3.5V to 5.5V
  2. Data, Outputs both Temperature and Humidity through serial Data
  3. NC, No Connection and hence not used
  4. Ground, Connected to the ground of the circuit

NOTE: In this demo, we will be using the DHT sensor with 3 pins, mounted to a small PCB and includes a required surface mounted pull up resistor for the Data line.

Wiring the DHT11 BCB mounted version to the NodeMCU is quite easy:

  • The Power supply pin of DHT11 to 3V of the node MCU.
  • The Data pin to GPIO2 (D4)

  • The ground to the ground

Step 3: Create an AskSensors Account

You need to create an AskSensors account.

Get free account at asksensors.com.

Step 4: Create Sensor

  1. Create new sensor to send data to.
  2. In this demo, we need to add at least two modules: The first module for the temperature and the second for the humidity. Refer to this tutorial for step by step guide helping how to create sensor and modules on AskSensors platform.

Don't forget to copy down your 'Api Key In', It is mandatory for the next steps.

Step 5: Writing the Code

I assume that you are programming the module using the Arduino IDE setup (version 1.6.7 or newer) as described here, and you have already made up this instructable, so you have the ESP8266 core and libraries installed, and you are able to connect your nodeMCU to internet through WiFi.

  1. Now, open up the Arduino IDE and head over to the library manager.
  2. Install the DHT library (You can also install it by going to Sketch > Include Library > Manage Libraries, and search for adafruit dht library)
  3. This example sketch reads temperature and humidity from DHT11 sensor and sends it AskSensors using HTPPS GET Requests. Get it from github and modify the following:
    • Set your WiFi SSID and password.
    • Set the API Key In provided by AskSensors to send data to.

    Change these three lines in the code:

    // user config: TODO
    const char* wifi_ssid = "..........";            // SSID
    const char* wifi_password = ".........";         // WIFI 
    const char* apiKeyIn = ".........";      // API KEY IN

    By default, the provided code reads DHT measurements and sends it to the AskSensors platform every 25 seconds. You can change it by modifying the line below:

    delay(25000);     // delay in msec

    Step 6: ​ Run the Code

    1. Connect the ESP8266 nodeMCU to your computer through a USB cable.
    2. Run the code.
    3. Open a serial terminal.
    4. You should see your ESP8266 connecting to internet through WiFi,
    5. Then, the ESP8266 will periodically reads the temperature and the humidity and send it to the askSensors.

    Step 7: Visualize Your Data in the Cloud

    Now, return back to AskSensors and visualize your modules data in graphs. If needed, you have also the option to export your data in CSV files that you can process using other tools.

    Step 8: Well Done!

    I hope that this tutorial helped you to build your system of temperature and humidity monitoring with the ESP8266 and the AskSensors cloud.

    You can find more tutorials here.

    1 Person Made This Project!


    • Raspberry Pi Contest

      Raspberry Pi Contest
    • Knitting and Crochet Speed Challenge

      Knitting and Crochet Speed Challenge
    • Anything Goes Contest 2021

      Anything Goes Contest 2021



    20 hours ago

    Hoping someone can help me. I have folowed the instructions and and It works initialy. when i start or reboot the processor it connects and sends the data the first two times bu when it trys to connect the third time it fails. If I reboot it dose the same.


    Question 2 years ago on Introduction

    How to change Temperature from Celsius to Fahrenheit?


    2 years ago

    Hello,i tried a similar project but im using arduino mega to display the temperature on an LCD,i want to make a kit that measures temp and humid but also upload the code on cloud,luckily i have been able to made it but despite that i want to modify the project that ask the user to input the ssid and password to connect to a network without going through programming.i searched about interfacing mini keyboard with the arduino or nodemcu,unfortunately all ive got is interfacing 4x4 matrix keypad.Any solution or idea for that guys? thanks

    MAD _A
    MAD _A

    Question 2 years ago

    Hello! thanks for detailed project! I already did all instructions, with successful upload code, however i get an error during serial monitoring (connection failed)
    14:07:02.369 -> ********** connecting to HOST : asksensors.com
    14:07:02.860 -> -> connection failed
    14:07:03.882 -> Temperature: 19.10 C
    14:07:03.882 -> Humidity: 81.00%
    14:07:03.882 -> ********** connecting to HOST : asksensors.com
    14:07:04.373 -> -> connection failed
    14:07:05.393 -> Temperature: 19.10 C
    14:07:05.393 -> Humidity: 81.00%
    14:07:05.393 -> ********** connecting to HOST : asksensors.com
    14:07:05.887 -> -> connection failed

    any help would be appreciated! thanks

    MAD _A
    MAD _A

    Reply 2 years ago

    Thanks for the reply! i just tried it it still does not show results on asksensors , by the way, i checked if my ESP8266 and it is working fine, i tested with the example sending random data to my module on ask sensors and it worked! however still not able to send my dht readings to asksensors, here's what i got from serial monitoring >
    23:01:31.930 -> ********** requesting URL: /api.asksensors/write/EWNo4tHcpMztIpsOI8FQ8MdBa5FFEXsL?module1=18.90&module2=82.00
    23:01:31.930 -> > Request sent to ASKSENSORS
    23:01:57.966 -> Temperature: 18.90 C
    23:01:57.966 -> Humidity: 81.00%
    23:01:57.966 -> ********** connecting to HOST : asksensors.com
    23:01:58.454 -> -> connection failed


    Reply 2 years ago

    Looks like your ESP8266 is not able to connect through HTTPS, I tried to send data to your sensor from the browser, it works fine.

    One of the fixes suggested by the AskSensors Community is to set the client to insecure by putting client.setInsecure(); in the setup function:

    I have tested it, it works as expected.

    MAD _A
    MAD _A

    Reply 2 years ago

    it is WORKING!!!! Thank you so much! :)


    3 years ago on Introduction

    il faut 3.5v pour dht11 ou 22 il faut mieux tirer l'alim du dut11/22 au 5v et mettre data au 3v


    Reply 3 years ago

    Bonjour Philippe,

    Oui, c'est ce qui est défini dans les specs. mais sa marche aussi bien avec
    3V3, une alim très accessible sur le kit, donc beaucoup plus simple :-).