Introduction

In this article, I'll let you know how to use DHT11 Sensor with the Arduino Uno to find humidity and temperature
Requirements
  • Arduino Uno
  • DHT11 Sensor
  • Bread Board
  • Led
  • Jumper Wires
Connection
  • Vcc to Arduino 5v
  • Data Out to Arduino Digital Pin 7
  • Gnd to Arduino Gnd
Led
  • Anode pin to the Arduino digital pin 13
  • Cathode pin to the Arduino Gnd
DHT11 Sensor
Programming
Please download the DHT library from the following link.
Go to Sketch, Include Library, then add Zip File.
  1. #include<dht.h>
  2. dht DHT;
  3. #define DHT11_PIN 7
  4. int led=13;
  5. int temperature;
  6. void setup()
  7. {
  8. Serial.begin(9600);
  9. pinMode(led,OUTPUT);
  10. Serial.println("TESTER PROGRAM HUMIDITY SENSOR");
  11. }
  12. void loop()
  13. {
  14. int chk=DHT.read7(DHT11_PIN);
  15. Serial.println("Humidity");
  16. Serial.println(DHT.humidity,1);
  17. Serial.println("Temperature");
  18. if(temperature>20)
  19. {
  20. digitalWrite(led,HIGH);
  21. }
  22. else{
  23. digitalWrite(led,LOW);
  24. }
  25. Serial.println(DHT.temperature,1);
  26. delay(1000);
  27. }
Explanation
  • Include the library first before you code set DHT11 sensor PIN as 7 and led as 13.
  • In the setup, function set the pinMode led as OUTPUT and set the baud rate like 9600.
  • In the loop function, we want to give the condition for DHT11 sensor DHT. Read the sensor value from the Arduino board.
  • And print the value in the serial monitor for humidity and temperature.
  • The led is HIGH if the temperature is greater than 20, else the led is LOW.
Output
Read more articles on Arduino: