Hello dear friends. Hope you will be fine. Today we will learn that how to use a DHT (DHT11 version) Temperature and Humidity Sensor. In this tutorial, you will see the result in the serial monitor of Arduino but later I will write some more tutorial for getting the result into the database and then generate the dynamic chart to show your sensor’s temperature and humidity. So let’ start our first tutorial of this series.
We need the following hardware for this project:
- DHT11, a temperature and humidity sensor.
- Wemos d1 mini or UNO arduino
- Three cables
Again we will be using a Library specifically designed for these sensors that will make our code short and easy to write.
As you can see we only need 3 connections to the sensor since one of the pin is not used.
The connections are : Voltage, Ground, and Signal which can be connected to any Analog Pin on our UNO.
Note: You can use UNO arduino for this project and set the pin as shown below.
You have to download DHT library for this project that is available for this sensor. I will try to make code very short and simple. Download link for DHT library is given below. Once you have the library, just go ahead and extract it to the Library folder inside your Arduino IDE software folder.
#define dht_apin D2 // Analog Pin sensor is connected to
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor
//Start of Program
Serial.print("Current humidity = ");
Serial.print("temperature = ");
delay(5000);//Wait 5 seconds before accessing sensor again.
//Fastest should be once every two seconds.
}// end loop()
Change pin port on line #define dht_apin D2.
You can download the Library we used here: DHT_Library.zip