Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Experiment 05

Reading Temperature and Relative Humidity Value from the Sensor

5.1 Introduction
DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity
sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog
input pins needed). It's fairly simple to use but requires careful timing to grab data. The only real downside of
this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor
readings can be up to 2 seconds old.

DHT11 is a relative humidity sensor. To measure the surrounding air this sensor uses a thermistor and a
capacitive humidity sensor. DHT11 has a Capacitive Sensor for measuring humidity & NTC Thermistor for
temperature sensing. (We will cover them in detail below). It calibrates the humidity using humidity
coefficients, which are stored in the OTP program memory of the built-in controller.

The temperature range of DHT11 is from 0 to 50 degree Celsius with a 2-degree accuracy. Humidity range of
this sensor is from 20 to 80% with 5% accuracy. The sampling rate of this sensor is 1Hz .i.e. it gives one
reading for every second. DHT11 is small in size with operating voltage from 3 to 5 volts. The maximum
current used while measuring is 2.5mA.

Components Required: Node MCU, DHT sensor, USB B Type Cable.

5.2 Working
The DHT - Digital Temperature and Humidity sensor is set to pin 2 and Blynk app is listened on Serial monitor
connection. The V0 pin is monitored continuously and any change results in calling dht() function.

The DHT sensor monitors the floating-point values of Temperature in °C and Humidity and writes to the
Blynk app through V2 pin. This dht() function repeats in loop for continuous monitoring of the values of
temperature and humidity.

The Node MCU is connected with the DHT11 sensor. The libraries such as:

• Adafruit library
• DHT sensor library
• Firebase ESP8266 library
• Blynk Library

Dept. of CSE, SaIT 2023-2024 17


IoT Laboratory Report

5.2.1 Steps:
1. Add the libraries by navigating to
2. Sketch >> Include Library >>
3. Add .zip library >> Select .zip file and load.
4. Thereby the values with respect to DHT can be obtained in real-time.

5.3 Implementation Code


#include <dht11.h>

#define DHT11PIN 4

dht11 DHT11;

void setup()

Serial.begin(9600);

void loop()

Serial.println();

int chk = DHT11.read(DHT11PIN);

Serial.print("Humidity (%): ");

Serial.println((float)DHT11.humidity, 2);

Serial.print("Temperature (C): ");

Serial.println((float)DHT11.temperature, 2);

delay(2000);

Dept. of CSE, SaIT 2023-2024 18


IoT Laboratory Report

5.4 Demonstration

Fig. 5.1 Hardware Setup for Measuring Temperature and Relative Humidity.

Fig. 5.2 Temperature and Humidity displayed over the Output Console.

Dept. of CSE, SaIT 2023-2024 19

You might also like