# Adafruit AM2320 Sensor

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/051/633/medium800/adafruit_products_3721_iso_ORIG_2018_03.jpg?1520443470)

This little sensor looks an _awful lot_ like the popular DHT11/DHT22 temperature and humidity sensors, but unlike classic DHT sensors, it has an I2C interface! That's right, you do not need to use a bit-bang timing-specific protocol to talk to the AM2320, it uses plain-old-I2C. Whew, that makes things a little easier, doesn't it?

**But!** &nbsp;We'll let you know, this sensor is not well documented like our other, fancier I2C temperature & humidity sensors. The datasheet mentions it has 3% humidity accuracy and 0.5C temperature accuracy, but we're not very trusting of the specifications. So, while this sensor does seem to work, it's not recommended for anything where you care about any sort of guaranteed accuracy. Temperature is probably correct to 2-3 degrees Celsius. Humidity is probably within 5-10%.

That said, for maker and IoT projects? You can't beat the simplicity and price! And we've got ready-to-go working Arduino and CircuitPython code to use it.

Each order comes with one AM2320, a low-cost temperature and humidity sensor. You just provide any microcontroller that can run our Arduino or CircuitPython library, and two I2C pull-up resistors (not included).

# Adafruit AM2320 Sensor

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/051/623/medium800/adafruit_products_pinout.jpg?1520441502)

Starting from the **left** the pins are

1. **VDD** - this is power in, can be 3-5VDC
2. **SDA** - I2C data in/out, requires a pullup of 2-10K to **VDD**
3. **GND** - this is signal/power ground
4. **SCL** - I2C clock in, requires a pullup of 2-10K to **VDD**

# Adafruit AM2320 Sensor

## Arduino Usage

You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C, then port the code - its pretty simple stuff!

![](https://cdn-learn.adafruit.com/assets/assets/000/051/624/medium800/adafruit_products_metrowire_bb.png?1520442056)

[metrowire fritzing](https://cdn-learn.adafruit.com/assets/assets/000/051/626/original/metrowire.fzz?1520442072)
- Connect **Vin** to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
- Connect **GND** to common power/data ground
- Connect the **SCL** pin to the I2C clock **SCL** pin on your microcontroller
- Connect the **SDA** pin to the I2C data **SDA** pin on your microcontroller.

You will also need to add two I2C pullup resistors if your board does not already have them. You can use 2.2K - 10K but we will just use 10K. The resistors go from **VDD** to **SCL** and **SDA** each.

The AM2320 has a default I2C address of **0x5C&nbsp;** and cannot be changed.

# Install Adafruit Sensor

Open up the Library Manager in the Arduino IDE...

![](https://cdn-learn.adafruit.com/assets/assets/000/051/627/medium800/adafruit_products_managelib.png?1520442244)

Search for **Adafruit\_Sensor** to locate the Unified Sensor library and **Install** it

![](https://cdn-learn.adafruit.com/assets/assets/000/051/628/medium800/adafruit_products_adafruitsensor.png?1520442285)

# Download Adafruit\_AM2320

To begin reading sensor data, you will need to also install the[&nbsp;Adafruit\_AM2320 library](https://github.com/adafruit/Adafruit_AM2320).

![](https://cdn-learn.adafruit.com/assets/assets/000/062/861/medium800/adafruit_products_image.png?1538448545)

We also have a great tutorial on Arduino library installation at:  
[http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use "Link: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use")

# Load Demo

Open up **File-\>Examples-\>Adafruit\_AM2320**** -\>am2320\_basictest** and upload to your microcontroller wired up to the sensor

![](https://cdn-learn.adafruit.com/assets/assets/000/051/629/medium800/adafruit_products_basictest.png?1520442452)

Thats it! Now open up the serial terminal window at 9600 speed to begin the test.

![](https://cdn-learn.adafruit.com/assets/assets/000/051/630/medium800/adafruit_products_basicout.png?1520442498)

You can try breathing on the sensor to increase the humidity.

# Adafruit AM2320 Sensor

## Python & CircuitPython

It's easy to use the AM2320 sensor with Python or CircuitPython and the&nbsp;[Adafruit CircuitPython AM2320](https://github.com/adafruit/Adafruit_CircuitPython_AM2320) module.&nbsp; This module allows you to easily write Python code that reads the humidity and temperature from the sensor.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

Warning: 

# CircuitPython Microcontroller Wiring

First wire up a AM2320 to your board exactly as shown on the previous pages for Arduino using an I2C connection.&nbsp; Here's an example of wiring a ItsyBitsy M0 to the sensor with I2C:

- **Board 3V** &nbsp;to&nbsp; **sensor VIN**
- **Board GND** &nbsp;to&nbsp; **sensor GND**
- **Board SCL** &nbsp;to&nbsp; **sensor SCL**
- **Board SDA** &nbsp;to&nbsp; **sensor SDA**

![adafruit_products_itsywire_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/051/631/medium640/adafruit_products_itsywire_bb.png?1538672784)

[itsywire fritzing](https://cdn-learn.adafruit.com/assets/assets/000/051/632/original/itsywire.fzz?1520443026)
# Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V3** to **sensor VIN**
- **Pi GND** to **sensor GND**
- **Pi SCL** to **sensor SCL**
- **Pi SDA** to **sensor SDA**

![adafruit_products_raspi_am2320_i2c_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/000/medium640/adafruit_products_raspi_am2320_i2c_bb.jpg?1538674755)

Info: 

# CircuitPython Installation of AM2320 Library

Next you'll need to install the&nbsp;[Adafruit CircuitPython AM2320](https://github.com/adafruit/Adafruit_CircuitPython_AM2320) library on your CircuitPython board.&nbsp;&nbsp;

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](../../../../welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).&nbsp; Our introduction guide has&nbsp;[a great page on how to install the library bundle](../../../../welcome-to-circuitpython/circuitpython-libraries)&nbsp;for both express and non-express boards.

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_am2320.mpy**
- **adafruit\_bus\_device**

You can also download the&nbsp; **adafruit\_am2320.mpy** &nbsp;from&nbsp;[its releases page on Github](https://github.com/adafruit/Adafruit_CircuitPython_AM2320/releases).

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_am2320.mpy,&nbsp;** and **&nbsp;adafruit\_bus\_device**** &nbsp; **files and folders** &nbsp;**copied over.

Next[&nbsp;connect to the board's serial REPL](https://learn.adafruit.com/welcome-to-circuitpython/the-repl) so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

# Python Installation of AM2320 Library

You'll need to install the Adafruit\_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. [Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-am2320`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

# CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll initialize it and read the humidity and temperature from the board's Python REPL.

Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

```python
import board
import adafruit_am2320
i2c = board.I2C()
sensor = adafruit_am2320.AM2320(i2c)
```

Now you're ready to read values from the sensor using any of these properties:

- **relative\_humidity** &nbsp;- The relative humidity measured by the sensor, this is a value from 0-100%.
- **temperature&nbsp;** - The temperature measured by the sensor, a value in degrees Celsius.

For example, to print the temperature and relative humidity:

```auto
print('Humidity: {0}%'.format(sensor.relative_humidity))
print('Temperature: {0}C'.format(sensor.temperature))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/063/001/medium800/adafruit_products_AM2320_REPL_print.png?1538675186)

Warning: 

That's all there is to using the AM2320 with CircuitPython!

Below is a complete example that measures the sensor readings and prints them every two seconds.&nbsp; Save this as **code.py** on your board and open the REPL to see the output.

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_AM2320/blob/main/examples/am2320_simpletest.py

# Adafruit AM2320 Sensor

## Python Docs


## Related Guides

- [Data Logging with Feather and CircuitPython](https://learn.adafruit.com/data-logging-with-feather-and-circuitpython.md)
- [Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython](https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython.md)
- [Bendable Sound Reactive Lamp with WLED](https://learn.adafruit.com/bendable-sound-reactive-lamp-with-wled.md)
- [DIY Trinkey No-Soldering USB Air Quality Monitor](https://learn.adafruit.com/diy-trinkey-no-solder-air-quality-monitor.md)
- [MX MIDI Guitar](https://learn.adafruit.com/mx-midi-guitar.md)
- [Adafruit EYESPI Breakout Board](https://learn.adafruit.com/adafruit-eyespi-breakout-board.md)
- [MagTag Daily Weather Forecast Display](https://learn.adafruit.com/magtag-weather.md)
- [ADXL345 Digital Accelerometer](https://learn.adafruit.com/adxl345-digital-accelerometer.md)
- [PyPortal IoT Weather Station](https://learn.adafruit.com/pyportal-iot-weather-station.md)
- [Adafruit OLED FeatherWing](https://learn.adafruit.com/adafruit-oled-featherwing.md)
- [LED Matrix Necklace Pendant](https://learn.adafruit.com/led-matrix-necklace-pendant.md)
- [Daily UV Index PyPortal Display](https://learn.adafruit.com/pyportal-uv-index.md)
- [Adafruit LPS28 Pressure Sensor](https://learn.adafruit.com/adafruit-lps28-pressure-sensor.md)
- [BLE Light Switch with Feather nRF52840 and Crickit](https://learn.adafruit.com/bluetooth-light-switch-with-crickit-and-nrf52840.md)
- [FruitBox Sequencer: Musically Delicious Step Pattern Generator ](https://learn.adafruit.com/circuitpython-fruitbox-sequencer-musically-delicious-step-pattern-generator.md)
