Arduino Code and Video for an Aosong AM2320 Digital Temperature and Humidity Sensor with LCD1602 and I2C Module
In this tutorial, we will explore how to use the Aosong AM2320 digital temperature and humidity sensor alongside an LCD1602 display that employs an I2C module. The goal is to display temperature readings in both Fahrenheit and Celsius, as well as relative humidity. This setup is ideal for monitoring environmental conditions in various projects, making it a versatile addition to your Arduino toolkit.

We will be using the AM2320 sensor to gather temperature and humidity data, which will then be displayed on the LCD1602. The I2C module simplifies the wiring process, requiring only four connections: VCC, GND, SDA, and SCL. For a clear understanding of the wiring and programming, I recommend watching the associated video (in video at 00:00).
Hardware Explained
The key components in this project include the AM2320 sensor, the LCD1602 display, and the I2C module. The AM2320 is a digital sensor that provides accurate readings of temperature and humidity through an I2C interface. It operates on a voltage of 3.3V to 5.5V and has a measurement range of -40°C to +80°C for temperature and 0% to 100% for humidity.
The LCD1602 display allows for the visualization of the sensor readings. It is a 16x2 character display that communicates via the I2C protocol, which reduces the number of required connections to just four. The I2C module converts the parallel data from the LCD to a serial format, making it easier to connect to the Arduino.
Datasheet Details
| Manufacturer | Aosong |
|---|---|
| Part number | AM2320 |
| Logic/IO voltage | 3.3 V - 5.5 V |
| Supply voltage | 3.3 V - 5.5 V |
| Output current | ≤ 1.5 mA |
| Measurement range (Temperature) | -40°C to +80°C |
| Measurement range (Humidity) | 0% to 100% |
| Response time | ≤ 2s |
| Package | DIP-4 |
| Notes / variants | Resistor pull-ups are recommended for I2C connections. |
- Ensure proper power supply within the specified voltage range.
- Use pull-up resistors (4.7kΩ recommended) for SDA and SCL lines.
- Check for correct I2C address (default is 0x27 for most LCDs).
- Handle potential errors by checking the sensor's error code.
- Clear the LCD before displaying new readings to avoid overlap.
Wiring Instructions

To wire the AM2320 sensor, connect the left pin (VCC) to 5V on the Arduino. The second pin (SDA) goes to the A4 pin on an Arduino Uno (or pin 20 on a Mega). The third pin (GND) should be connected to the ground, and the fourth pin (SCL) connects to the A5 pin on an Arduino Uno (or pin 21 on a Mega). Additionally, connect a 4.7kΩ resistor between the SDA pin and 5V, and another 4.7kΩ resistor between the SCL pin and 5V to ensure proper signal levels.
For the LCD1602 display with I2C, connect the VCC pin to 5V and the GND pin to ground. Connect the SDA pin from the LCD to the same SDA pin (A4) used for the sensor. Similarly, connect the SCL pin from the LCD to the same SCL pin (A5) used for the sensor. This shared wiring allows both devices to communicate over the same I2C bus.
Code Examples & Walkthrough
The following code initializes the AM2320 sensor and the LCD1602 display. It begins by including the necessary libraries and creating an instance of the sensor.
#include
AM2320 sensor;
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
Here, the sensor object is created from the AM2320 library, and the lcd object is initialized with the I2C address of the display.
In the setup() function, we initialize both the sensor and the LCD. This includes turning on the backlight and printing an initial message.
void setup() {
sensor.begin();
lcd.begin();
lcd.backlight();
lcd.print("Robojax AM2320 ");
lcd.setCursor (0,1);
lcd.print("LCD1602 I2C Demo");
delay(3000);
}
This code sets up the display to show a welcome message for 3 seconds, allowing time for the user to see that the system is initializing.
The loop() function continuously checks for sensor measurements and updates the display accordingly. If a measurement is available, it clears the screen and prints the temperature in both Fahrenheit and Celsius, along with the relative humidity.
void loop() {
if (sensor.measure()) {
lcd.clear();
lcd.print("T:");
lcd.print(temp('F'));
lcd.print("F/");
lcd.print(temp('C'));
lcd.print("C");
lcd.setCursor (0,1);
lcd.print("R.H. :");
lcd.print(sensor.getHumidity());
lcd.print("%");
}
else {
int errorCode = sensor.getErrorCode();
switch (errorCode) {
case 1: lcd.print("ERR: Sensor offline"); break;
case 2: lcd.print("ERR: CRC failed."); break;
}
}
delay(500);
}
This excerpt demonstrates how the program retrieves and displays the sensor data while handling any potential errors by checking the errorCode.
Demonstration / What to Expect
When the setup is complete, expect the LCD to display the temperature in both Fahrenheit and Celsius, as well as the relative humidity percentage. If the sensor is offline or there’s a CRC error, the display will show corresponding error messages. It’s important to ensure all connections are secure to avoid any issues (in video at 02:45).
Video Timestamps
- 00:00 - Introduction to the project
- 01:30 - Wiring instructions
- 03:15 - Code explanation
- 04:45 - Demonstration of functionality
Things you might need
-
Amazon
-
AliExpressPurchase AM2302 or DHT11 or DHT22 sensor from AliExpresss.click.aliexpress.com
Resources & references
-
ExternalAM2320 Library (from GitHub)github.com
-
ExternalArduino Wire Documentation pagearduino.cc
Files📁
Datasheet (pdf)
-
Adafruit-am2320-temperature-humidity-i2c-sensor user's manual
application/pdf1.27 MB
Fritzing File
-
AM2320 Humidity and Temperature Sensor
application/zip0.01 MB