Interfacing Temperature & Humidity Sensor with Arduino

In the tutorial Interfacing Temperature & Humidity Sensor with Arduino I will tell you that how can you interface temperature ...

Interfacing DHT11 with arduino, Interfacing temperature sensor with arduino, Interfacing humidity sensor with arduino, How to interface DHT11 with arduino, How to interface temperature sensor with arduino, How to interface humidity sensor with arduinoHello everyone! I hope you all will be absolutely fine and having fun. In the tutorial Interfacing Temperature & Humidity Sensor with Arduino I will tell you that how can you interface temperature and humidity sensor named as DHT11 with Arduino and how can you observe the temperature and humidity level using this sensor. This sensor has usually three pins but some of its types has four pins but only the three pins are of importance for us e.g. VCC, GND and the third pin for reading the data from the sensor.In the tutorial Interfacing Temperature & Humidity Sensor with Arduino, I will make a simple Arduino program which will estimate the level of temperature and humidity continuously and will display the value of both temperature and humidity on the serial monitor. You will see that the sensor will give different readings for the different environments.

Temperature & Humidity Sensor with Arduino

I will tell you the step by step procedure that how can you interface DHT11 sensor with Arduino and how to make a simple program in Arduino software to read the data continuously from the sensor and how to display the obtained data on the serial monitor. You can also display this data on Liquid Crystal Display (LCD) as I have discussed in detail in my previous tutorial DC Motor Direction Control using Arduino, DC Motor Speed Control using Arduino, Stepper Motor Direction Control in Arduino and Stepper Motor Speed Control using Arduino.
  • You can download the complete source code here by clicking on the button below.
  • Download .rar file, extract this file and enjoy the complete simulation code.

Block Diagram

  • First of all, I would like to explain you the algorithm with the help of a block diagram.
  • It will help in better understanding of an algorithm.
  • The block diagram for interfacing of temperature and humidity sensor with Arduino is given in the figure below.
Interfacing DHT11 with arduino, Interfacing temperature sensor with arduino, Interfacing humidity sensor with arduino, How to interface DHT11 with arduino, How to interface temperature sensor with arduino, How to interface humidity sensor with arduino
  • Power supply in necessary to turn the whole system ON.
  • DHT11 is connected with the Arduino UNO.
  • Arduino UNO reads the data from the DHT11 sensor and displays the obtained data on the serial monitor.
  • That data will also be displayed on the LCD.

Circuit Diagram

  • The complete wiring diagram for this project is shown in the figure below.
Interfacing DHT11 with arduino, Interfacing temperature sensor with arduino, Interfacing humidity sensor with arduino, How to interface DHT11 with arduino, How to interface temperature sensor with arduino, How to interface humidity sensor with arduino
  • You can run this project properly, by making the circuit first, identical to the circuit diagram shown in the figure above.
  • The analog pin A3 of the Arduino UNO will help us in reading the data from the sensor.
  • The other two pins of the sensor are connected to the supply of 5V and ground respectively as you can see from the above figure.

Flow Chart

  • The flow chart will help you to understand the flow of the program while executing.
  • The flow chart for this project is shown in the figure below.
Interfacing DHT11 with arduino, Interfacing temperature sensor with arduino, Interfacing humidity sensor with arduino, How to interface DHT11 with arduino, How to interface temperature sensor with arduino, How to interface humidity sensor with arduino
  • The data from the sensor can be estimated on the serial monitor only after opening the serial port
  • Then data will be displayed on the LCD and at end serial port must be closed in order to avoid the exchange of unwanted commands.

Source Code Description

  • The source code for this project is given below.
  • You have to just copy and paste the code given below in your Arduino software after properly interfacing DHT11 with the Arduino.
  • After uploading the code onto your Arduino board you will be able to observe the humidity and temperature and humidity level on serial monitor.
#include<dht.h>// DHT11 humidity sensor library
#include<LiquidCrystal.h> //LCD library
dht DHT; //Creating sensor object
#define DHT11_PIN A3 // Sensor is connected to Arduino pin 3
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);// LCD connected with Arduino on these pins
void setup()
{
  Serial.begin(9600); //setting baud rate
  Serial.println("   =====================================================");
  Serial.println("   ||   Welcome to Temperarue and Humidity Detector   ||");
  Serial.println("   =====================================================");
  Serial.println("");
  lcd.begin(20, 4); // initialinzing the LCD order
  lcd.setCursor(4,1); //Setting the cursor on LCD
  lcd.print("Welcome to");//printing on LCD
  lcd.setCursor(2,2);
  lcd.print("Humidity detector");
  delay(2000);//adding delay of 2 secons or 2000 msec
  }
void loop()//method used to run the code repeatedly
{
  int chk = DHT.read11(DHT11_PIN); //Reading data from sensor
  Serial.print(" Humidity = ");//prints on the serial monitor
  Serial.print(DHT.humidity);// prints obtained humidity on serial port
  Serial.print(" g/m^3");

  lcd.clear();//clears all the data on LCD
  delay(1000);//adding delay of 1 second
  lcd.display(); //starting the display of LCD after clearing
  lcd.setCursor(0,0);
  lcd.print("Humidity=");
  lcd.print(DHT.humidity);
  lcd.print(" g/m^3");
  
  Serial.print("    \tTemperature = ");//prints on the serial monitor
  Serial.print(DHT.temperature, 1);//prints obtained temperature on serial port
  Serial.println(" degrees");

  lcd.setCursor(0,1);
  lcd.print("Temperature=");//prints on LCD
  lcd.print(DHT.temperature, 1);//prints the obtained temperature on LCD
  lcd.print(" deg");

  lcd.setCursor(1,2);
  lcd.print("www.TheEngineering");
  lcd.setCursor(4,3);
  lcd.print("Projects.com");

  delay(2000);//adding the delay of 2 seconds
  }  
  • I am going to explain you that how this code is working!
  • First of all I have added the library in the libraries folder at the destination where the Arduino software is installed.
  • I have defined DHT11’s library in the source code then.
  • Then I have defined the library for LCD.
  • I have defined the pin at which DHT11 is attached with the Arduino board.
  • Then I have defined the Arduino pins at which the LCD in interface.
  • Then by opening the serial port I have started to print the level of temperature and humidity on the serial monitor as well as on the 20×4 LCD.
  • At the end, I have added the delay of 2 seconds so that the speed of the data to be printed on the serial monitor can be reduced to some extent in order to observe properly.
  • This was the brief description of the source code.
That is all from the tutorial Interfacing Temperature & Humidity Sensor with Arduino. I hope you enjoyed this tutorial. If you are facing any problem regarding any of my tutorials, you can ask me freely in the comments without even feeling any kind of hesitation, I will try my level best to solve you issues in a better way, if possible. I will explore Arduino by making further projects and will share them with you as well. So, till then, Take Care :)

Leave a Reply

Leave a Reply