Adafruit AHT20 Temperature & Humidity Sensor
Adafruit AHT20 Temperature & Humidity Sensor
The AHT20 is a nice but inexpensive temperature and humidity sensor from the same folks that brought us the
DHT22 (https://adafru.it/sb4). You can take sensor readings as often as you like, and it uses standard I2C so its super
easy to use with any Arduino or Linux/Raspberry Pi board.
This sensor has a typical accuracy of +- 2% relative humidity, and +-0.3 °C. There is only one I2C address so its not a
good option when you need multiple humidity sensors.
Power Pins
The sensor on the breakout requires between a 2.7V and 5.5V, and can be easily used with most microcontrollers
from an Arduino to a Feather or something else.
VIN - this is the power pin. To power the board, give it the same power as the logic level of your microcontroller -
e.g. for a 5V micro like Arduino, use 5V
GND - common ground for power and logic
The final results should resemble the illustration above, showing an Adafruit Metro development board.
Installation
You can install the Adafruit AHTx0 Library for Arduino using the Library Manager in the Arduino IDE:
Then follow the same process for the Adafruit BusIO library.
Load Example
Open up File -> Examples -> Adafruit AHTx0 -> adafruit_aht_test and upload to your Arduino wired up to the sensor.
Upload the sketch to your board and open up the Serial Monitor (Tools->Serial Monitor). You should see the the values
for temperature and humidity.
Example Code
The following example code is part of the standard library, but illustrates how you can retrieve sensor data from the
AHT20 for the temperature and humidity values:
You should get something resembling the following output when you open the Serial Monitor at 115200 baud:
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://adafru.it/BSN).
First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/Amd) for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these
libraries from Adafruit's CircuitPython library bundle (https://adafru.it/uap). Our CircuitPython starter guide has a great
page on how to install the library bundle (https://adafru.it/ABU).
Copy the following files from the bundle to the lib folder on your CIRCUITPY drive:
adafruit_ahtx0.mpy
adafruit_bus_device
Before continuing make sure your board's lib folder or root filesystem has the adafruit_ahtx0.mpy, and
adafruit_bus_device file and folder copied over.
Next connect to the board's serial REPL (https://adafru.it/Awz)so you are at the CircuitPython >>> prompt.
Once that's done, from your command line run the following command:
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!
Run the following code to import the necessary modules and initialize the I2C connection with the sensor:
import board
import adafruit_ahtx0
sensor = adafruit_ahtx0.AHTx0(board.I2C())
Now you're ready to read values from the sensor using these properties:
import time
import board
import adafruit_ahtx0
while True:
print("\nTemperature: %0.1f C" % sensor.temperature)
print("Humidity: %0.1f %%" % sensor.relative_humidity)
time.sleep(2)
Schematic
Fab Print