Table of Contents
Introduction:
When you are designing systems that will respond or work according to real-world parameters like temperature, pressure, humidity, etc… So you need to keep track of the values of the physical parameter and process accordingly. To do this we have many sensors which will give these parameter values in their respective units. So in this project, we are going to interface the DHT11 sensor which will give you the temperature and humidity of the real world. In this project, we will display the data on a serial monitor if you want to display the data on LCD follow this tutorial to know How to interface I2C LCD.
How DHT and Arduino communicate:
Arduino, send a pulse signal of HIGH to LOW with a delay of about 18µs to detect the DHT module and wait for the DHT sensor to respond. When the DHT sensor receives the HIGH to LOW signal it sets the line to LOW for 80µs and again DHT sets the line to HIGH for 80µs. This means it gives a pulse with a width of 80µs of LOW and HIGH and prepares itself to send the data. After that when the communicating line is LOW, DHT again makes it HIGH for 80µs and starts preparing the actual data to transmit in that line.
The data stream consists of bits and every bit consists of “0”s and “1” with 50µs of a LOW pulse at the beginning.
As the distance between the DHT sensor and Arduino is < 10cm we are not using any resistor to pull up the data line. It is recommended to use a pull-up resistor according to the distance between Arduino and DHT sensor.
Hardware Requirements:
Disclaimer: It contains Amazon affiliate links. which means I can get a small commission on the sale. This might be your indirect help to me. Thank You 🙏
Software Requirements:
Arduino IDE (You can download it from HERE).
Arduino DHT Library.
Circuit diagram:
Code Explanation:
First we need to include the library we are going to use in this code.
#include <dht.h>
Then we need to create an object to call the DHT library constructor.
dht DHT;
The below line defines the pin A0 of Arduino where we will get the data from the DHT sensor.
#define DHT11_PIN A0
Full source code:
#include <dht.h>
#define DHT11_PIN A0
dht DHT;
void setup(){
Serial.begin(9600);
Serial.print(char(169)); //Copyright Symbol
Serial.println(" Myengineeringstuffs.com");
delay(2000);
}
void loop()
{
DHT.read11(DHT11_PIN);
Serial.print("Humidity: ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print(" Temperature: ");
Serial.print(DHT.temperature);
Serial.print(char(176));
delay(1000);
}