In this article we look at another temperature and humidity sensors – this time its the AHT20 and we will connect it to our Microbit and see what it can do
First lets take a look at the sensor in question, this is from the datasheet
AHT20, as a new generation of temperature and humidity sensors, has established a new standard in size and intelligence.
It is embedded in a double row flat no-lead package suitable for reflow soldering, with a bottom of 3 x 3 mm and a height of 1.0 mm.
The sensor outputs calibrated digital signals in standard IAHT20, as a new generation of temperature and humidity sensors, has established a new standard in size and intelligence.
It is embedded in a double row flat no-lead package suitable for reflow soldering, with a bottom of 3 x 3 mm and a height of 1.0 mm.
The sensor outputs calibrated digital signals in standard I2C format. The AHT20 is equipped with a newly designed ASIC chip, an improved MEMS semiconductor capacitive humidity sensing element and a standard on-chip temperature sensing element.
Supply voltage | DC : 2.0 – 5.5V |
Measuring range (humidity) | 0 ~ 100% RH |
Measuring range (temperature) | -40 ~ + 85 ℃ |
Humidity accuracy | ± 2 % RH ( 25 ℃ ) |
Temperature accuracy | ± 0.3 ℃ |
Resolution | temperature: 0.01℃ Humidity: 0.024%RH |
Response time | temperature: 5s humidity: 8s 1/e (63%) |
Output signal | I2C signal |
Parts Required
Once again for ease of use I connect an expansion board to the microbit, I feel this makes it easier to connect to a sensor like the one pictured above using connecting wire
Name | Link |
Microbit | Offical Microbit V2 Development Board |
AHT20 | AHT20 Temperature and Humidity Sensor Module High-precision Humidity Sensor |
Connecting wire | Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire |
expansion board | micro: bit expansion board |
Schematic/Connection
The layout below shows a Microbit, I used a Microbit v1
If you have an ESP32 board with a STEMMA QT cables, you can use these:
Black for GND
Red for V+
Blue for SDA
Yellow for SCL
Code Example
This example uses a couple of libraries, both of which can be installed using the library manager. if you search for the AHT20 one first and you are using a newer version of the Arduino IDE it will install the other one as well – which makes things a bit easier.
You need the Adafruit library for the AHT20 from https://github.com/adafruit/Adafruit_AHTX0
You also need an I2C support library from the same folks for the library above to work and that is available from – https://github.com/adafruit/Adafruit_BusIO
This is the simple test example that comes with the library
[codesyntax lang=”cpp”]
#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); }
[/codesyntax]
Output
Open the serial monitor and you should see something like this
Temperature: 20.99 degrees C
Humidity: 43.30% rH
Temperature: 20.99 degrees C
Humidity: 43.32% rH
Temperature: 21.01 degrees C
Humidity: 43.27% rH
Temperature: 20.99 degrees C
Humidity: 43.32% rH
Temperature: 21.74 degrees C
Humidity: 42.96% rH
Links