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

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

Intro: DHT11 Temperature and Humidity Monitoring Using the ESP8266 and the AskSensors IoT Platform

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 and humidity from 20% to 90% with an accuracy of ±1°C and ±1%.

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-bitAccuracy: ±1°C and ±1%

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.

    Share

      Recommendations

      • Tiny Home Contest

        Tiny Home Contest
      • Metalworking Contest

        Metalworking Contest
      • Furniture Contest 2018

        Furniture Contest 2018

      2 Discussions

      0
      None
      askSensorsPhilippeL40

      Reply 21 days 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 :-).