What is the DHT11 Temperature & Humidity Sensor??
DHT11 sensors are made of humidity sensing elements and thermistors. Humidity is the amount of water vapor present in the air. The DHT11 sensor measures water vapor by measuring the electrical resistance between two electrodes. The humidity sensing element consists of two electrodes that hold moisture. When water vapor is absorbed by electrodes due to increased conductivity resistance decreases. When humidity is less then conductivity is less and resistance becomes high. Cold air can hold less water vapor before it becomes saturated, and hot air can hold more water vapor before it becomes saturated.
How does DHT11 Sensor Works??
DHT-11 sensor has IC-onboard which is used for calibration. The values are calibrated by a pre-define coefficient and converted the analog values to a digital values. So no need to use analog pins as sensors consist of ADC. These digital values of temperature or humidity are sent to the Arduino board. DHT11 senses temperature range between 0°c to 50°c and humidity range from 20 % to 80 %.
DHT11 Specifications
- Operating Voltage: 3.5V to 5.5V
- Operating current: 0.3mA (measuring) 60uA (standby)
- Temperature Range: 0°C to 50°C
- Humidity Range: 20% to 90%
- Accuracy: ±1°C and ±1%
Applications of DHT11
- Measure temperature and humidity
- Local Weather station
- Air conditioning systems
- Industries & burier furnace
- Heating and ventilation chambers
- In homes & offices
Parts Required
- DHT 11 (Temperature and humidity module)
- Arduino
- Jumper wires
- Breadboard
Schematic Diagram
Connect the ground pin of the DHT-11 sensor to the ground pin of Arduino, the VCC pin to 5v, and the Signal pin to 12.
Click on Sketch then go to include a library and click on manage libraries where you can find tons of libraries for different sensors.
In the search box search for DHT-11 press enter, and you will find many libraries for the search results. then click on the DHT sensor library by Adafruit and install that library.
Code
#define DHTPIN 12 // DHT sensor pin connected to Arduino
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22
//#define DHTTYPE DHT21 // DHT 21
DHT dht(DHTPIN, DHTTYPE); // Creates a dht object & passing parameters dht-pin & dht-sensor-type
void setup() {
Serial.begin(115200); // set baud rate to 115200
dht.begin(); // initize the sensor
}
void loop() {
float h = dht.readHumidity(); // read value of humidity
float t = dht.readTemperature(); // read value of temperature in Celsius
float f = (t*9.0/5.0) + 32.0; // converting value of temperature in celsius to Fahrenheit
Serial.print("|");
Serial.print(" Humidity: ");
Serial.println(h); // print the value of humidity
Serial.print("Temperature: ");
Serial.print(t); // print the value of temperature in Celsius
Serial.print("°C ");
Serial.print("|");
Serial.print(f); // print the value of temperature in Fahrenheit
Serial.print("°F");
delay(200);
}
First include that library "DHT.h" initialize pins of DHT-11 sensor to pin 12 of Arduino. We have selected DHT TYPE to DHT11 as we are using that sensor module. we have created an object of DHT and passed the parameter inside it such as the DHT pin which pins we have connected the sensor to and the DHT type which sensor module board we are using. We also configure the baud rate to 115200 and initialize the sensor.
In the void loop, we are reading values from DHT 11 sensor such as temperature and humidity and storing them in a variable which we are printed on the Serial monitor. the temperature that we get from DHT 11 library is Celsius so we converted Celsius to Fahrenheit using a formula.
we have also introduced a delay of 200 milliseconds here.
Now we used the serial monitor to observe the output. . To open up the serial monitor, click on Tools > Serial Monitor or use the shortcut (SHIFT + CONTROL + M). You can see output on Serial monitor values of temperature in Celsius, Fahrenheit, and Humidity.
Conclusion -
Today
we learn about what is Temperature & humidity sensor, how to use Temperature & humidity sensors with Arduino & working principle of Temperature & humidity sensors.
"I hope you find this IoT blog very helpful to you. In the upcoming lesson, we will see more about IoT sensors till then bye. See you all in my next blog."