top of page

Measuring Humidity and temperature using DHT11 sensor with Arduino.


What is a Digital Humidity Temperature Sensor?


DHT11 is a Humidity and Temperature Sensor, which generates calibrated digital output. DHT11 can be interface with any microcontroller like Arduino, Raspberry Pi, etc. and get instantaneous results. DHT11 is a low-cost humidity and temperature sensor which provides high reliability and long-term stability.


Material Required:


Material Quantity

Arduino Uno 1

DHT11 Sensor 1

Jumper cables 3


Pinout Diagram:



Working:


Ok now let’s see how these sensors work. They consist of a humidity sensing component, an NTC temperature sensor (or thermistor) and an IC on the back side of the sensor.




For measuring humidity they use the humidity sensing component which has two electrodes with moisture holding substrate between them. So as the humidity changes, the conductivity of the substrate changes or the resistance between these electrodes changes. This change in resistance is measured and processed by the IC which makes it ready to be read by a microcontroller.




On the other hand, for measuring temperature these sensors use an NTC temperature sensor or a thermistor. A thermistor is a variable resistor that changes its resistance with the temperature change. These sensors are made by sintering semiconductive materials such as ceramics or polymers to provide larger changes in the resistance with just small temperature changes. The term “NTC” means “Negative Temperature Coefficient”, which means that the resistance decreases with an increase in the temperature.


Circuit Diagram: The DHTxx sensors have four pins, VCC, GND, data pin and a not connected pin which has no usage. A pull-up resistor from 5K to 10K Ohms is required to keep the data line high and to enable the communication between the sensor and the Arduino Board. There are some versions of these sensors that come with a breakout board with a built-in pull-up resistor and they have just 3 pins.


The DHTXX sensors have their single wire protocol used for transferring the data. This protocol requires precise timing and the timing diagrams for getting the data from the sensors can be found in the datasheets of the sensors. However, we don’t have to worry much about these timing diagrams because we will use the DHT library which takes care of everything.


Tested Programming Code:

First, we need to include the DHT library which can be found from the Arduino official website or can be downloaded from the following link https://github.com/adidax/dht11 then define the PIN to which our sensor is connected and create a DHT object. In the setup section, we need to initiate the serial communication because we will use the serial monitor to print the results. Using the read22() function we will read the data from the sensor and put the values of the temperature and the humidity into the t and h variables. If you use the DHT11 sensor you will need to you the read11() function. In the end, we will print the temperature and the humidity values on the serial monitor.


#include "DHT.h"

#define DHTPIN 2

DHT dht(DHTPIN, DHTTYPE);

void setup() {

Serial.begin(9600);

Serial.println("DHTxx test!");

dht.begin();

}

void loop() {

measurements. delay(2000);

float h = dht.readHumidity();

float t = dht.readTemperature();

float f =dht.readTemperature(true);


if (isnan(h) || isnan(t) || isnan(f))

{ Serial.println("Failed to read from DHT sensor!");

return;

}

float hi = dht.computeHeatIndex(f, h);

Serial.print("Humidity: ");

Serial.print(h);

Serial.print(" %\t");

Serial.print("Temperature: ");


Serial.print(t);

Serial.print(" *C ");

Serial.print(f);

Serial.print(" *F\t");

Serial.print("Heat index: ");

Serial.print(hi);

Serial.println(" *F");

}


After we will upload this code to the Arduino board, the temperature and humidity results from the sensor can be seen on the Serial monitor.

Precautions:

  1. Double-check the connections before powering on the circuit.

  2. Don’t use loose jumper cables.

  3. Check whether the proper board is selected from Arduino IDE.

  4. Ensure proper placement of sensor for correct working.

  5. Don’t put the sensor in any fluid or water, this is meant for taking ambient readings only.



Conclusion:


You can successfully measure temperature and humidity using the DHT11 sensor. Many more other applications can be made and triggered using the DHT11 sensor.


Output:


Situation Screenshot: Serial Monitor (Ctrl+Shift+M)





GET IN TOUCH

We'd love to hear from you

bottom of page