Skip to Content

AM2320 digital temperature and humidity sensor Arduino tutorial

AM2320 digital temperature and humidity sensor Arduino tutorial

In this tutorial, you will learn how to use the AM2320 digital temperature and humidity sensor with Arduino. I have included a wiring diagram and example code to help you get started!

For this tutorial, we will be using the Adafruit Unified Sensor library in combination with the Adafruit AM2320 sensor library. These libraries make communicating with the sensor via I2C super easy. In the first part of this article, you can find the specifications and pinout of the AM2320. Next, we will look at how to connect the sensor to the Arduino.

The example sketch at the end of this tutorial can be used to take temperature readings from the sensor and display the results in the Serial Monitor.

If you would like to learn more about other temperature sensors, check out the articles below.

Recommended articles

If you have any questions, please leave a comment below.


Supplies

Hardware components

AM2320 digital temperature and humidity sensor× 1Amazon
Arduino Uno× 1Amazon
Breadboard× 1Amazon
Jumper wires× 4Amazon
USB cable type A/B× 1Amazon

Software

Arduino IDEArduino IDE

Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.


About the AM2320

The AM2320 is a low-cost digital temperature and humidity sensor made by ASAIR. This sensor is similar to the popular DHT11/DHT22 sensors but also features an I2C interface instead of the single bus communication protocol that many of the other DHTxx sensors use. You can find a dedicated tutorial for the DHT11 and DHT22 here:

The sensor consists of a capacitive moisture sensing element and a high precision integrated temperature measuring element connected to a microprocessor. The temperature measuring range of the sensor is -40 to 80 degrees Celsius, with a stated accuracy of ± 0.5 °C. 

Relative humidity

When you look at the datasheet of the sensor, you will see that it measures the relative humidity (RH) of the air and not the absolute humidity. But what’s the difference? The absolute humidity is the amount of water vapor in the air (expressed in g/m³), regardless of temperature. The relative humidity does take temperature into account.

The relative humidity is the ratio between the actual amount of water vapor present in the air and the maximum amount of water vapor that the air can hold at a given temperature.

Warm air can hold more water than cold air. This means that for the same amount of water vapor in the air, the relative humidity in cool air will be higher than that in warm air. At 100 percent relative humidity, the air is saturated and is at its dewpoint.

AM2320 pinout

The pinout of the sensor is as follows:

PinNameDescription
1VDDPositive power supply pin (3.1 – 5.5 V)
2SDASerial data, bidirectional port
3GNDGround
4SCLSerial clock input port (single bus ground)

The default I2C address of the sensor is 0x5C and cannot be changed.

You can find more specifications of the sensor in the table below.

AM2320 specifications

Supply voltage3.1 – 5.5 V
Power consumptionSleep: 10 μA
Measuring: 950 μA
Humidity range0 – 99.9 % RH ± 3 % RH
Temperature range-40 – 80 °C ± 0.5 °C
InterfaceI2C
1-Wire
Sampling period2.0 s
Body dimensions15 x 12.1 x 4.5 mm
CostCheck price

For more information, you can check out the datasheet here:

AM2320 dimensions

Wiring – Connecting AM2320 to Arduino

Connecting the AM2320 to the Arduino is very easy as you can see in the diagram below.

AM2320 digital temperature and humidity sensor with Arduino wiring diagram
AM2320 digital temperature and humidity sensor with Arduino wiring diagram

The connections are also given in the table below

AM2320 connections

AM2320Arduino
Pin 1 (VDD)5 V
Pin 2 (SDA)A4
Pin 3 (GND)GND
Pin 4 (SCL)A5

If you are not using an Arduino Uno, the SDA and SCL pins can be at a different location. An Arduino Uno with the R3 layout (1.0 pinout), also has the SDA (data line) and SCL (clock line) pin headers close to the AREF pin. Check the table below for more details.

BoardSDASCL
Arduino UnoA4A5
Arduino NanoA4A5
Arduino Micro23
Arduino Mega 25602021
Arduino Leonardo23
Arduino Due2021
SDA and SCL pin locations on different Arduino boards.

Installing the required Arduino libraries

For this tutorial, we will be using the Adafruit Unified Sensor library and the Adafruit AM2320 sensor library.

To install these libraries, go to Tools > Manage Libraries (Ctrl + Shift + I on Windows) in the Arduino IDE. The Library Manager will open and update the list of installed libraries.

Now search for ‘adafruit unified sensor‘ and look for the Adafruit Unified Sensor library. Select the latest version and then click Install.

Install the Adafruit AM2320 sensor library in the same way.


AM2320 temperature and humidity sensor Arduino example code

The following example code can be used to take temperature and humidity readings from the sensor and display the results in the Serial Monitor of the Arduino IDE.

You can upload the example code to your Arduino using the Arduino IDE.

To copy the code, click on the button in the top right corner of the code field.

/* Example code for AM2320 I2C temperature and humidity sensor with Arduino. More info: www.www.makerguides.com */

//  Include the required libraries:
#include <Adafruit_Sensor.h>
#include <Adafruit_AM2320.h>

// Create a new instance of the Adafruit_AM2320 class:
Adafruit_AM2320 AM2320 = Adafruit_AM2320();

void setup() {
  // Begin serial communication at a baud rate of 9600:
  Serial.begin(9600);

  // Setup the sensor;
  AM2320.begin();
}

void loop() {
  // Read the temperature and the humidity:
  float tempC = AM2320.readTemperature();
  float tempF = tempC * 1.8 + 32; // converts Celsius to Fahrenheit
  float humidity = AM2320.readHumidity();

  // Print the temperature and humidity in the Serial Monitor:
  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.print(" \xC2\xB0"); // shows degree symbol
  Serial.print("C  |  ");
  Serial.print(tempF);
  Serial.print(" \xC2\xB0"); // shows degree symbol
  Serial.println("F");
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %RH");

  // Wait 2 seconds between readings:
  delay(2000);
}

You should see the following output in the Serial Monitor (Ctrl + Shift + M):

Make sure that the baud rate in the Serial Monitor is also set to 9600.

How the code works

The first step is to include the Adafruit AM2320 and Unified Sensor library.

//  Include the required libraries:
#include <Adafruit_Sensor.h>
#include <Adafruit_AM2320.h>

Next, you need to create a new instance of the Adafruit_AM2320 class. In this case, I called the sensor ‘AM2320’ but you can use other names as well, like ‘temperature_sensor’.

// Create a new instance of the Adafruit_AM2320 class:
Adafruit_AM2320 AM2320 = Adafruit_AM2320();

In the setup(), we start serial communication at a baud rate of 9600. Make sure that the Serial Monitor is also set to 9600. We also initialize the sensor with AM2320.begin().

void setup() {
  // Begin serial communication at a baud rate of 9600:
  Serial.begin(9600);

  // Setup the sensor;
  AM2320.begin();
}

In the loop section of the code, I start by taking temperature and humidity readings from the sensor with the functions readTemperature() and readHumidity(). Note that readTemperature() returns the temperature in Celsius.

  // Read the temperature and the humidity:
  float tempC = AM2320.readTemperature();
  float tempF = tempC * 1.8 + 32; // converts Celsius to Fahrenheit
  float humidity = AM2320.readHumidity();

Lastly, I print the results in the Serial Monitor and add a delay between the readings. The minimum interval between readings is 2 seconds (see datasheet), so I added a 2 second delay.

  // Print the temperature and humidity in the Serial Monitor:
  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.print(" \xC2\xB0"); // shows degree symbol
  Serial.print("C  |  ");
  Serial.print(tempF);
  Serial.print(" \xC2\xB0"); // shows degree symbol
  Serial.println("F");
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %RH");

  // Wait 2 seconds between readings:
  delay(2000);

Conclusion

In this tutorial, I have shown you how to use the AM2320 temperature and humidity sensor with Arduino. I hope you found it useful and informative. If you did, please share it with a friend who also likes electronics and making things!

I would love to know what projects you plan on building (or have already built) with this sensor. If you have any questions, suggestions, or if you think that things are missing in this tutorial, please leave a comment below.

Note that comments are held for moderation to prevent spam.

Creative Commons License