Temperature and Humidity Sensor Module With Arduino

by Webotricks in Circuits > Arduino

46 Views, 1 Favorites, 0 Comments

Temperature and Humidity Sensor Module With Arduino

Untitled design (1).png

This project uses an Arduino Uno and a DHT11 sensor to measure temperature and humidity, calculate the heat index, and display the data on the serial monitor.

In this lesson, you’ll learn how to measure temperature and humidity, as well as calculate the heat index using a DHT11 sensor with an Arduino Uno. We’ll cover reading and interpreting data from the DHT11 sensor, and displaying these values along with the heat index in both Celsius and Fahrenheit on the serial monitor. This project is perfect for Arduino beginners, providing hands-on experience with sensors and data handling in a simple yet engaging way.

Supplies

Components and Supplies


1 USB-Cable - Buy Now


1 DHT11 Humidity & Temperature Sensor Module - Buy Now



1 Jumper-Wires - Buy Now



1 Arduino-Uno - Buy Now



1 Breadboard- Buy Now

Gather the Required Components

Before starting, make sure you have the following components:

Arduino Uno – The microcontroller board used for processing sensor dataDHT11

Temperature & Humidity Sensor – The sensor that measures temperature and humidity

Breadboard – Used for circuit prototyping

Jumper Wires (Male-to-Male) – For making connections

USB Cable – To connect the Arduino to the computer for programming and power


Circuit Connections

Untitled design (3).png

Now, let’s wire the DHT11 sensor to the Arduino Uno as shown in the diagram below.

Connect the VCC pin of the DHT11 sensor to the 5V pin on the Arduino Uno. Next, connect the Data Out pin of the sensor to Digital Pin 2 on the Arduino. Finally, connect the GND pin of the sensor to the GND pin on the Arduino.

Important: Some DHT11 modules have four pins. If yours includes an NC (Not Connected) pin, simply ignore it.

Install the DHT11 Library in Arduino IDE

Before writing the code, we need to install the DHT11 library in Arduino IDE.

Steps to Install the Library:

Open Arduino IDE.

Go to Sketch → Include Library → Manage Libraries.

In the search bar, type “DHT sensor library”.

Install "DHT sensor library by Adafruit".

Code

Code:

#include <DHT.h>
#define DHTPIN 2 // Connect the Data pin of DHT11 to Digital Pin 2
#define DHTTYPE DHT11 // Define the sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature(); // Read temperature in Celsius
float temperatureF = temperatureC * 1.8 + 32; // Convert to Fahrenheit
float heatIndexC = dht.computeHeatIndex(temperatureC, humidity, false); // Heat index in Celsius
float heatIndexF = dht.computeHeatIndex(temperatureF, humidity); // Heat index in Fahrenheit
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print(" °C / ");
Serial.print(temperatureF);
Serial.print(" °F\t");
Serial.print("Heat Index: ");
Serial.print(heatIndexC);
Serial.print(" °C / ");
Serial.print(heatIndexF);
Serial.println(" °F");
delay(2000); // Wait for 2 seconds before updating values
}