Search
Close this search box.

DHT11 Humidity Sensor with ESP8266 and ThingSpeak

In the previous project, I have shown you how to connect ESP8266 to ThingSpeak. After that initial setup, you can proceed with integrating various sensors with ESP8266 and monitoring the data on ThingSpeak API. So, in this project, I’ll show you how to interface DHT11 Humidity Sensor with ESP8266 and ThingSpeak and monitor the data.

Overview

DHT11 is a low-cost Humidity and Temperature Sensor. Since it has both the temperature and humidity sensors, the DHT11 Sensor is sufficient to implement your first IoT Weather Monitoring System.

When it comes to IoT, the combination of ESP8266 and ThingSpeak is an excellent way for beginners and hobbyists to dive into your IoT related projects.

If you are planning to build your own weather station, then this project could be your first step in that path. In this project, I’ll talk about the DHT11 Sensor in brief and also explain how to interface the DHT11 Humidity and Temperature Sensor with ESP8266 and ThingSpeak. 

DHT11 Humidity Sensor with ESP8266 and ThingSpeak Image

A Brief Note on DHT11 Sensor

DHT11 and DHT22 are a pair of cheap but efficient Humidity Sensors which can measure Relative Humidity and Temperature. Out of these two, the DHT11 Sensor is a cheaper version with a fairly good range of both Humidity and Temperature.

The Relative Humidity range of DHT11 is 20-95% with an accuracy of +/- 5%. Coming to the Temperature, the range is 0-500C with an accuracy of +/- 20C.

DHT11 Sensor

DHT22 Sensor has a wider range for both Humidity and Temperature with more accurate results but is costlier and bulkier than DHT11.

Both these sensors use a single pin for communication using 1-Wire Bus between the Microcontroller and the Sensor. The output from this single data pin is digital and hence, you don’t need an Analog Input pins on the Microcontroller. This is very useful as the ESP8266 ESP-01 Module doesn’t have any Analog Input Pins.

Interfacing DHT11 Humidity Sensor with ESP8266 and ThingSpeak

I’ll interface the DHT11 Sensor with ESP8266 through one of the GPIO Pins. All the calculations regarding the Humidity and Temperature will be performed in the ESP8266 Module.

After measuring the Temperature and Humidity, the results will be posted on the ThingSpeak API and can be seen as a graph.

Circuit Diagram

The circuit diagram for Interfacing DHT11 Humidity Sensor with ESP8266 and ThingSpeak is shown in the image below.

DHT11 Humidity Sensor with ESP8266 and ThingSpeak Circuit Diagram

Components Required

  • Arduino
  • DHT11 Humidity Sensor
  • ESP8266
  • Jumper Wires
  • Mini Breadboard
  • Resistors (1 KΩ and 2.2 KΩ)
  • Push Button
  • Slide Switch

Code

The code for connecting DHT11 Humidity Sensor with ESP8266 and ThingSpeak API is given below. You have to change the code i.e. add your WiFi Network’s SSID and Password at appropriate places.

Also, you need to note down your Write API Key from ThingSpeak Channel and paste it in the code.

In the previous project “CONNECT ESP8266 TO THINGSPEAK”, I have shown you how to create a channel in ThingSpeak and add fields for that channel. So, if you are unfamiliar with that information, please refer to that project.

NOTE:

  • You have to download two libraries called “DHT” and “Adafruit_Sensor”. You can download these libraries from these links: DHT and Adafruit_Sensor.
  • Download them in zip format, extract the contents and copy the folders to Documents–>Arduino–>libraries

Working

Make all the connections as per the circuit diagram. Here, I’ll be uploading the code directly to the ESP8266 Module. This means that the existing code or firmware will be erased.

Before uploading the code, connect the GPIO0 to GND and RESET the ESP Module to enable Programming Mode.

Also, select “Generic ESP8266 Module” in the Boards section of the Arduino IDE. Make sure that you have selected the correct COM PORT.

After uploading the code, first, disconnect the GPIO0 from GND (you can let is float) and RESET the ESP Module.

Now, if you open the Serial Monitor and set the baud rate to 115200 and also select “Both NL & CR” option, you can see the progress of the ESP8266 Module.

DHT11 Humidity Sensor with ESP8266 and ThingSpeak Serial

First, it will get connected to the WiFi Network. Then, immediately, it will try to read the data from the DHT11 Humidity sensor and calculate the Temperature and Humidity values based on that data.

After this, the values of temperature and humidity will be uploaded to the ThingSpeak API. If you open your channel in the ThingSpeak, you can see the chart associated with the values from the DHT11 Sensor.

DHT11 Humidity Sensor with ESP8266 and ThingSpeak API

Conclusion and Applications

  • In this simple project, I have shown you how to interface DHT11 Humidity Sensor with ESP8266 and ThingSpeak API.
  • You can monitor the DHT11 Sensor Data from anywhere in the World just by sitting in front of a computer.  
  • This project could be your first implementation towards a bigger and better Weather Station with many other sensors.      

 

17 Responses

    1. Arduino doesn’t need any code. I’m using it as an USB-to-Serial Converter. In fact, I have removed the Microcontroller from the Arduino Board.

  1. Unfortunatly not working. In console i get:

    Connecting to
    MYWIFI
    **
    ***WiFi connected***
    Temperature: 26.00deg C. Humidity: 18.00%. Connecting to Thingspeak.
    Sending….

    But it not sending this to cloud,

  2. Thank you for your great tutorials. It helps me achieve things I never thought I would. I do have a question – I’m carrying out a similar project but i’m using an MQ135 sensor to monitor air quality and provide notification through SMS when the quality is poor. With the help of your tutorials I’ve been able to program my ESP8266 WiFi module board to send and SMS to a certain mobile number. How do I cause the ESP8266 to work together with the rest of my arduino code? Do I create a new function for it in my main arduino sketch and call the function once my MQ135 reads poor quality? Do I trigger the ESP8266 by resetting it? Is that possible? Please help me out. Thank you

  3. Can you plz help me to get the ESP8266wifi library ? I have searched in google but none worked out during compilation.

  4. Connecting to
    MYWIFI
    **
    ***WiFi connected***
    Temperature: 26.00deg C. Humidity: 18.00%. Connecting to Thingspeak.
    Sending….

    But it not sending this to cloud,

  5. Hello,
    I am trying to add a soil sensor to this as well. I have successfully gotten the Humidity Sensor DHT11 to work connect and display, but I was curious how to add a Soil Sensor on A0 so that it would transmit to Thinkspeak as well?

    Any assistance would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *