Arduino is an advanced microcontroller board that can be interfaced with different sensors to measure different parameters. Using an Arduino board with DHT11 sensor we can take real time temperature and humidity readings. This article will cover steps required for DHT11 sensor interfacing with Arduino Uno board.
This tutorial covers following content:
1: Introduction to DHT11 Sensor
3: Installing the Required Libraries
4: Interfacing Arduino with DHT11 Sensor
1: Introduction to DHT11 Sensor
DHT11 is one of the commonly used temperature and humidity monitoring sensors in the electronics community. It is more precise in giving temperature and relative humidity. It outputs a calibrated digital signal which spits out into two different readings of temperature and humidity.
It uses the digital-signal-acquisition technique that gives reliability and stability. The DHT11 sensor contains a resistive-type humidity measuring component and features a NTC temperature measuring component. Both these are integrated to an 8-bit highly efficient microcontroller which offers fast response, anti-interference ability and cost-effectiveness.
Here are some main technical specifications of DHT11:
- DHT11 sensor operates at a voltage of 5V to 5.5V
- Operating current while measuring is 0.3mA and during standby time is 60uA
- It output serial data in digital signal
- Temperature of DHT11 sensor range from 0°C to 50°C
- Humidity Range: 20% to 90%
- Resolution: Temperature and Humidity both are 16-bit
- Accuracy of ±1°C for temperature measuring and ±1% for relative humidity readings
As we have covered a basic introduction to DHT11 sensor now let’s move towards the pinout of DHT11.
2: DHT11 Sensor Pinout
Most of the time the DHT11 sensor comes in two different pin configurations. The DHT11 sensor which comes in 4 pins configuration has 3 pins not working or labeled as no connection.
The 3 pin DHT11 sensor module comes in three pins which include power, GND and data pin.
2.1: 3 Pin DHT11 Sensor
Given image shows 3 pin configurations of the DHT11 sensor.
These three pins are:
1 | Data | Output temperature and humidity in serial data |
2 | Vcc | Input power 3.5V to 5.5V |
3 | GND | GND of circuit |
2.2: 4 Pin DHT11 Sensor
Following image illustrate 4 pin DHT11 sensor module:
These 4 pins include:
1 | Vcc | Input power 3.5V to 5.5V |
2 | Data | Output temperature and humidity in serial data |
3 | NC | No connection or not used |
4 | GND | GND of circuit |
3: Installing the Required Arduino Libraries
To interface the DHT11 sensor with Arduino some necessary libraries need to be installed. Without using these libraries DHT11 cannot show us the real time temperature reading over the serial monitor.
Open Arduino IDE, go to: Sketch>Include Library>Manage Libraries
Alternatively, we can also open the library manager from the side button on the Arduino IDE interface.
Search for the DHT library and install the latest updated version. The DHT library will help to read sensor data.
After installing the DHT library next we have to install a unified sensor library by Adafruit.
We have successfully installed required libraries and now we can interface Arduino Uno with DHT11 easily.
4: Interfacing Arduino with DHT11 Sensor
For interfacing Arduino with DHT11 sensor we need a digital pin for reading sensor data and to power DHT11 sensor we can either use the 5V pin or Vin pin of Arduino.
4.1: Schematic
In the given image we can see the schematic diagram of Arduino with DHT11. This image represents the 3-pin sensor module interfacing with Arduino. Remember to connect a pull up resistor of 10kΩ.
Similarly, 4 pin DHT11 can also be connected, the only difference here is the 3 pin which is of no use or termed as No connection. The data pin is at pin 2 of the sensor
4.2: Hardware
After designing the same circuit as in schematic, we can see the hardware image of Arduino as shown below:
4.3: Code
Connect Arduino with PC and open Arduino IDE. Upload the given code to the Arduino board.
#define DHTPIN 4 /*Digital pin 4 for sensor input*/
#define DHTTYPE DHT11 /*type of DHT sensor we are using*/
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin(); /*initialize DHT sensor working*/
}
void loop() {
delay(2000);
float h = dht.readHumidity(); /*variable to store humidity*/
float t = dht.readTemperature(); /*variable to store temperature in Celsius*/
float f = dht.readTemperature(true); /*variable to store temperature in Fahrenheit*/
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print(F("Humidity: ")); /*prints humidity value*/
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C ")); /*prints temperature in Celsius*/
Serial.print(f);
Serial.println(F("°F ")); /*prints temperature in Fahrenheit*/
}
The code started by including the DHT library. An Arduino digital pin 4 is initialized for reading the temperature and humidity. After that DHT11 sensor is defined. Three variables h, t and f are created which stores the data values for humidity, temperature in Celsius and Fahrenheit in float format.
At the end of the program each of them is printed on a serial monitor.
4.4: Output
In the output terminal of IDE, we can see the humidity and temperature readings printed.
We have successfully completed interfacing of Arduino with DHT11 sensor.
Conclusion
Arduino is a multi-dimensional device that can enhance its working by interfacing different sensors. Here in this lesson, we have configured an Arduino Uno board with a DHT11 sensor to measure the temperature and humidity of a room. Using the Arduino code provided any of the DHT11 sensors can be configured to take readings.