In this project, we will be using the Arduino Nano and DHT11 sensor to create a temperature and humidity monitoring system. The Arduino Nano will read data from the DHT11 sensor and display the temperature and humidity readings on the screen.
This tutorial covers following content:
- 1: Introduction to DHT11 Sensor
- 2: DHT11 Sensor Pinout
- 2.1: 3 Pin DHT11 Sensor
- 2.2: 4 Pin DHT11 Sensor
- 3: Installing the Required Libraries
- 4: Interfacing Arduino Nano with DHT11 Sensor
- 4.1: Schematic
- 4.2: Hardware
- 4.3: Code
- 4.4: Output
1: Introduction to DHT11 Sensor
The DHT11 sensor is a compact and low-cost device for measuring temperature and humidity. DHT11 sensor is widely used for designing portable weather stations, HVAC systems, and home automation systems.
The DHT11 sensor consists of a humidity sensing element and a temperature sensing element, which are combined on a single integrated circuit. The sensor is capable of measuring both relative humidity and temperature, and it can transmit this data via a digital signal to a microcontroller or other device.
The DHT11 sensor is easy to interface and control using Arduino code. It can be connected to a microcontroller or single-board computer using jumper wires and a breadboard, and it can be easily integrated into a variety of projects.
Some main specification of DHT11 sensor includes:
- Operating voltage is 3.5V to 5.5V
- DHT11 current while measuring readings is 0.3mA and standby current is 60uA
- Temperature measured from 0°C to 50°C
- Humidity values from 20% to 90%
- Resolution: Temperature and Humidity both are 16-bit
- Accuracy of ±1°C for temperature measuring and ±1% for relative humidity readings
Now we covered the basics of the DHT11 sensor. Let’s move towards the DHT11 sensor pinout.
2: DHT11 Sensor Pinout
DHT11 sensor comes in two different variants one with 4 pins configuration and other one with 3 pin configurations. Only difference here is that the 4 pin DHT11 sensor has an extra pin with no connection. This pin is labeled as NC and not used for any purpose.
The 3 pins of DHT11 sensor are:
- GND pin
- Power Pin
- Digital output signal data pin.
2.1: 3 Pin DHT11 Sensor
Below is the pinout of the three pin DHT11 sensor.
Description of three pin of DHT11 sensor is:
1 | Data | Output temperature reading and real time humidity |
2 | Vcc | Input voltage of 3.5V to 5.5V |
3 | GND | GND pin |
2.2: 4 Pin DHT11 Sensor
Below is the 4 pin DHT11 sensor pinout:
These 4 pins of DHT11 sensor includes:
1 | Vcc | Input voltage of 3.5V to 5.5V |
2 | Data | Output temperature and humidity |
3 | NC | No connection or not used |
4 | GND | GND |
3: Installing the Required Arduino Libraries
To measure readings using the DHT11 sensor we have to install some libraries in the Arduino IDE. Using the DHT11 sensor library we can display temperature and humidity real time values on Arduino serial monitors.
Open IDE then go to: Sketch>Include Library>Manage Libraries
After opening the library manager in the IDE, search the DHT11 library and install the updated version. Using this library, we can read sensor values.
After installing the DHT11 sensor library now install the unified sensor library:
We have successfully installed both libraries and now we will interface DHT11 with Arduino Nano.
4: Interfacing Arduino Nano with DHT11 Sensor
For interfacing Arduino Nano with DHT11 sensor we need to power it using the Vin or 3V3 pin of the Nano board and a digital pin to read real time values from the sensor output signal pin.
4.1: Schematic
The below image shows three pins DHT11 sensor schematic diagram with Arduino Nano board. Here we have used a 3-pin sensor module and a pull up resistor of 10kΩ is connected with the output signal pin of the DHT11 sensor.
Similarly, the 4 pin DHT11 sensor is connected with Arduino Nano board, only difference is the third pin here is of no use and labeled as No connection (NC). Pin 2 of DHT11 is a data pin.
4.2: Hardware
Following is the hardware image of Arduino Nano with DHT11 sensor:
4.3: Code
Connect Arduino Nano with PC and upload given code to Nano board using the IDE.
#define DHTPIN 4 /*Nano pin 4 for DHT11 sensor input*/
#define DHTTYPE DHT11 /*DHT sensor type we are using*/
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin(); /*Starts DHT sensor*/
}
void loop() {
delay(2000);
float h = dht.readHumidity(); /*float variable that stores humidity value*/
float t = dht.readTemperature(); /*float variable that 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 temp in Celsius*/
Serial.print(f);
Serial.println(F("°F ")); /*prints temp in Fahrenheit*/
}
At the start of the code, we included the DHT11 library. Arduino Nano digital pin 4 will read temperature and humidity values from the sensor. After that three variables h, t and f are defined to store the humidity and temperature readings.
Lastly, all three values are printed on the Arduino serial monitor:
4.4: Output
Output terminal represents the temperature and humidity values measured every 2 seconds:
We have completed interfacing of Arduino Nano with DHT11.
Conclusion
Arduino Nano is a compact microcontroller board with multi-dimensional capabilities. It can be interfaced with multiple sensors using the GPIO pins. Here in this lesson, we have interfaced Arduino Nano with a DHT11 sensor module and measured the real time temperature and humidity values of the room. Using Arduino code any DHT11 sensors can be interfaced with Arduino Nano boards.