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.
- #include<dht.h>
- dht DHT;
- #define DHT11_PIN 7
- int led=13;
- int temperature;
- void setup()
- {
- Serial.begin(9600);
- pinMode(led,OUTPUT);
- Serial.println("TESTER PROGRAM HUMIDITY SENSOR");
-
- }
- void loop()
- {
- int chk=DHT.read7(DHT11_PIN);
- Serial.println("Humidity");
- Serial.println(DHT.humidity,1);
- Serial.println("Temperature");
- if(temperature>20)
- {
- digitalWrite(led,HIGH);
- }
- else{
- digitalWrite(led,LOW);
- }
- Serial.println(DHT.temperature,1);
- delay(1000);
- }
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 baudrate as 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 temperature is greater than 20, else the led is LOW.
Output
Read more articles on Arduino: