Contents

Interfacing AM2301/DHT21 Temperature & Humidity Sensor Module with Arduino

What is AM2301 Sensor?

The AM2301 module is an internally-calibrated digital sensor that measures temperature and humidity. It can measure humidity from 0 to 99.9% with an accuracy of ±2% and temperatures from -40 to 80°C with an accuracy of ±3°C.

This digital module uses a single-wire protocol for communication. So, apart from the power supply pins, it only needs one digital pin to communicate with the microcontroller. Using this protocol, we can transfer data through this line for a maximum distance of 20 meters.

DHT21another name for this moduleis one of the well-known families of “DHT temperature and humidity sensors.” The specifications of DHT21 and DHT22 are very similar, except for the main differences, including the case design and the physical appearance of the output pins—AM2301 has three wires for the output, whereas DHT22 uses metal pins.

DHT21

AM2301 Sensor Specifications

  • Operating voltage: 3.3 to 5.5 volts
  • Communication protocol: single-wire digital
  • Maximum distance for data transmission on the data line: 20 meters
  • Operating temperature: -40 to 80°C
  • Temperature resolution: 0.1℃ (16 bits)
  • Temperature measurement accuracy: ±0.3°C
  • Humidity measurement range: 0 to 99.9% relative humidity
  • Humidity measurement accuracy: ±3%

For more information, you can download the datasheet below.

Pinout of AM2301 (DHT21) Module

  • Red wire: positive pin of the module power supply (3.3 to 5.5 volts)
  • Black wire: ground
  • Yellow wire: data line (must be connected to one of the digital pins of the microcontroller)

The image below shows the internal parts and dimensions of the module.

DHT21 Dimensions

Required Materials

Hardware Components

Arduino UNO R3 × 1
AM2301 Temperature & Humidity Module × 2
Jumper Wire × 3

Software

Arduino IDE

Interfacing AM2301/DHT21 Temperature & Humidity Sensor Module with Arduino

Step 1: Wiring

Connect the wires as shown below.

Step 2: Installing Library

Install the DHT library in Arduino IDE.

You can download the zip file of the DHT library from this link.

If you need more help installing the library, click on this link.

Step 3: Code

Copy and run the following code in Arduino.


//Libraries
#include <DHT.h>;

//Constants
#define DHTPIN 2 //what pin we're connected to
#define DHTTYPE DHT21 //DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE); //Initialize DHT sensor for normal 16mhz Arduino


//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value

void setup()
{
 Serial.begin(9600);
 dht.begin();
}

void loop()
{
 //Read data and store it to variables hum and temp
 hum = dht.readHumidity();
 temp= dht.readTemperature();
 
 //Print temp and humidity values to serial monitor
 Serial.print("Humidity: ");
 Serial.print(hum);
 Serial.print("%, Temperature: ");
 Serial.print(temp);
 Serial.println(" Celsius");
 
 delay(2000); //Delay 2 sec.
}

After uploading the code on the Arduino board, open the serial monitor window to see the output.

If everything is done correctly, the temperature and humidity data in the serial output of the monitor should look something like the following image.

As the temperature or humidity of the environment changes, you should see the appropriate changes in the serial output in order to make sure that the module is working properly. For example, the output temperature should change quickly by lighting a fire near the sensor.

Differences Between DHT11, DHT22, and DHT21 (AM2301)

Range and accuracy of temperature measurement

  • DHT11: -20 to 60°C with an accuracy of ±2°C
  • DHT21: -40 to 80°C with an accuracy of ±0.3°C
  • DHT22: -40 to 80°C with an accuracy of ±0.5°C

Range and accuracy of humidity measurement

  • DHT11: 5 to 95% with an accuracy of ±5%
  • DHT21: 0 to 99% with an accuracy of ±2%
  • DHT22: 0 to 99% with an accuracy of ±2%

To interface DHT11 and DHT22 sensors, you can visit this link.

Liked What You See?​
Get Updates And Learn From The Best​

Leave a Reply

Your email address will not be published. Required fields are marked *