- If you are running a Feather (3.3V), connect Feather 3V to board VIN
- If you are running a 5V Arduino (Uno, etc.), connect Arduino 5V to board VIN
- Connect Feather or Arduino GND to board GND
- Connect Feather or Arduino SCL to board SCL
- Connect Feather or Arduino SDA to board SDA
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:
Click the Manage Libraries ... menu item, search for Adafruit AHTx0, and select the Adafruit AHTx0 library:
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:
#include <Adafruit_AHTX0.h> Adafruit_AHTX0 aht; void setup() { Serial.begin(115200); Serial.println("Adafruit AHT10/AHT20 demo!"); if (! aht.begin()) { Serial.println("Could not find AHT? Check wiring"); while (1) delay(10); } Serial.println("AHT10 or AHT20 found"); } void loop() { sensors_event_t humidity, temp; aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH"); delay(500); }
You should get something resembling the following output when you open the Serial Monitor at 115200 baud:
Text editor powered by tinymce.