Arduino Nano - DHT11

This tutorial instructs you how to use Arduino Nano to read the temperature and humidity from DHT11 sensor. In detail, we will learn:

We suggest:

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×DHT11 Temperature and Humidity Sensor
1×DHT11 Temperature Humidity Sensor Module (short)
1×10 kΩ resistor
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of DHT11 Temperature and Humidity Sensor

The DHT11 Temperature and Humidity Sensor Pinout

The DHT11 on the market comes with two forms: sensor and module.

The DHT11 sensor has four pins:

  • GND pin: must be connected to GND (0V)
  • VCC pin: must be connected to VCC (5V)
  • DATA pin: used for communication between the sensor and Arduino Nano
  • NC pin: not necessary, this pin can be disregarded
DHT11 temperature and humidity sensor pinout

The DHT11 module has three pins:

  • GND pin (-): must be connected to GND (0V)
  • VCC pin (+): must be connected to VCC (5V)
  • OUT pin: used for communication between the sensor and Arduino Nano

※ NOTE THAT:

The arrangement of pins on a module may differ from one manufacturer to another. It is essential to always refer to the labels printed on the module when using it. Take a close look!

Wiring Diagram

Arduino Nano - DHT11 Sensor Wiring

A resistor with a resistance between 5K and 10K Ohms is necessary to keep the data line high, thus enabling communication between the sensor and the Arduino Nano.

The wiring diagram between Arduino Nano and DHT11 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

Arduino Nano - DHT11 Module Wiring

The DHT11 sensor module comes with a built-in resistor, eliminating the need for extra wiring or soldering. This saves us time and effort.

The wiring diagram between Arduino Nano and DHT11 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

How To Program For DHT11 Temperature Sensor

  • The first step is to include the library:
#include "DHT.h"
  • Specify the Arduino Nano pin that is connected to the DHT11 sensor.
#define DHT_PIN 3 // Arduino Nano pin connected to DHT11 sensor
  • Specify the type of sensor: DHT11
#define DHT_TYPE DHT11
  • Create a DHT object.
DHT dht11(DHT_PIN, DHT_TYPE);
  • Begin the sensor setup process:
dht11.begin();
  • Read the humidity value.
float humi = dht11.readHumidity();
  • Read the temperature in Celsius.
float temperature_C = dht11.readTemperature();
  • Read the temperature in Fahrenheit.
float temperature_F = dht11.readTemperature(true);

Arduino Nano Code for DHT11

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-dht11 */ #include "DHT.h" #define DHT_PIN 3 // The Arduino Nano pin connected to DHT11 sensor #define DHT_TYPE DHT11 DHT dht11(DHT_PIN, DHT_TYPE); void setup() { Serial.begin(9600); dht11.begin(); // initialize the sensor } void loop() { // wait a few seconds between measurements. delay(2000); // read humidity float humi = dht11.readHumidity(); // read temperature as Celsius float temperature_C = dht11.readTemperature(); // read temperature as Fahrenheit float temperature_F = dht11.readTemperature(true); // check if any reads failed if (isnan(humi) || isnan(temperature_C) || isnan(temperature_F)) { Serial.println("Failed to read from DHT sensor!"); } else { Serial.print("Humidity: "); Serial.print(humi); Serial.print("%"); Serial.print(" | "); Serial.print("Temperature: "); Serial.print(temperature_C); Serial.print("°C ~ "); Serial.print(temperature_F); Serial.println("°F"); } }

Detailed Instructions

  • Connect a USB cable to the Arduino Nano and the PC.
  • Open the Arduino IDE, select the appropriate board and port.
  • Click to the Libraries icon on the left bar of the Arduino IDE.
  • Search for “DHT” and locate the DHT sensor library by Adafruit.
  • Press the Install button to install the library.
Arduino Nano DHT11 sensor library
  • You will be prompted to install some other library dependencies.
  • To install all of them, simply click the Install All button.
Arduino Nano Adafruit Unified sensor library
  • Copy the code for your sensor and open it in Arduino IDE.
  • Click the Upload button in Arduino IDE to compile and upload the code to the Arduino Nano.
  • Change the temperature of the environment around the sensor.
  • Check the results on the Serial Monitor.
COM6
Send
Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 32.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 29.00°C ~ 84.20°F Humidity: 32.00% | Temperature: 29.00°C ~ 84.20°F Humidity: 31.00% | Temperature: 29.00°C ~ 84.20°F
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Additional Knowledge

Let's compare DHT11 and DHT22 sensors.

The commons between DHT11 and DHT22

  • Pinouts remain the same.
  • The wiring to an Arduino Nano is identical.
  • Programming, with the help of a library, is comparable, with only one line of code being distinct.

The differences between DHT11 and DHT22

DHT11 DHT22
Price ultra low cost low cost
Temperature Range 0°C to 50°C -40°C to 80°C
Temperature Accuracy ± 2°C ± 0.5°C
Humidity Range 20% to 80% 0% to 100%
Humidity Accuracy 5% ± 2 to 5%
Reading Rate 1Hz (once every second) 0.5Hz (once every 2 seconds)
Body size 15.5mm x 12mm x 5.5mm 15.1mm x 25mm x 7.7mm

It is evident that the DHT22 is more precise than the DHT11, has a wider range, yet is more costly.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!