Introduction
The AHT20 is a high-precision but low-cost temperature and humidity sensor, which is equipped with an improved MEMS semiconductor capacitive humidity sensor element. It features standard I2C interface and a wide voltage supply of 2V - 5V. And with simple peripheral circuit, it performs stably even in harsh environments in the measuring range of -40 - +85℃.
This sensor can be widely used for measuring the environmental temperature and humidity of home electronic equipment, the temperature and humidity of automobiles and so on.
Features
- Digital output, I2C interface
- Excellent long-term stability
- Quick response, strong anti-interference ability and strong ability to adapt to the environment
- Gravity interface, simple wiring, no soldering required
Applications
- Testing Equipment
- Automatic Control
- Data Loggers
- Weather Control
Specification
Module Parameters
- Operating Voltage: DC2V~5V
- Operating Current: 0.27mA (at 3.3V)
- Communication Protocol: I2C
- I2C Address: 0x38
- Dimension: 30mm×20.5mm/1.18×0.81"
AHT20 Chip Parameters
Relative Humidity
- Resolution: 0.024 %RH
- Accuracy: ±2 %RH
- Repeatability: ±0.1 %RH
- Hysteresis: ±1 %RH
- Non-linear: ±0.1 %RH
- Response Time: 8S
- Operating Range: 0~100 %RH
- Long-term Drift: <0.5 %RH/yr
Temperature
- Resolution: 0.01℃
- Accuracy Error: ±0.3℃
- Repeatability: ±0.1℃
- Hysteresis: ±0.1℃
- Response Time: minimum 5S, maximum 30S
- Operating Range: -40℃~85℃
- Long-term Drift: <0.04℃/yr
Dimension Diagram
Pinout
Pin | Function | Description |
---|---|---|
+ | Positive Power Supply | Power Supply: DC 2V~5V |
- | Negative Power Supply | -- |
SCL | I2C Clock Line | -- |
SDA | I2C Data Line | -- |
Tutorial
AHT20 Temperature and Humidity Sensor Reading Test
Hardware Requirement
- DFRduino UNO R3 (or similar) x 1
- SEN0528 Gravity: AHT20 Temperature and Humidity Sensor x 1
- M-M/F-M/F-F Jumper wires
Software Requirement
- Arduino IDE
- Download and install the DFRobot_AHT20 Library (About how to install the library?)
Connection Diagram
UNO Board: 3V3 - connect to - AHT20:+
UNO Board: GND - connect to - AHT20:-
UNO Board: SCL - connect to - AHT20:C
UNO Board: SDA - connect to - AHT20:D
Sample Code
The following code will read the measured values from the AHT20 temperature and humidity sensor and print them through the serial port.
#include "DFRobot_AHT20.h"
DFRobot_AHT20 aht20;
void setup(){
Serial.begin(115200);
while(!Serial){
}
uint8_t status;
while((status = aht20.begin()) != 0){
Serial.print("AHT20 sensor initialization failed. error status : ");
Serial.println(status);
delay(1000);
}
}
void loop(){
if(aht20.startMeasurementReady(true)){
Serial.print("temperature(-40~85 C): ");
Serial.print(aht20.getTemperature_C());
Serial.print(" C, ");
Serial.print(aht20.getTemperature_F());
Serial.print(" F\t");
Serial.print("humidity(0~100): ");
Serial.print(aht20.getHumidity_RH());
Serial.println(" %RH");
delay(8000);
}
}
Test Process
The results are as shown in the figure below, the temperature values in ℃ and ℉, and humidity values are displayed in the serial monitor.
Library Function Definition
/**
* @fn DFRobot_AHT20
* @brief DFRobot_AHT20 constructor
* @param wire TwoWire class object reference
* @return NONE
*/
DFRobot_AHT20(TwoWire &wire = Wire);
/**
* @fn begin
* @brief Initialize AHT20 sensor
* @return Init status value
* @retval 0 Init succeeded
* @retval 1 _pWire is NULL, please check if the constructor DFRobot_AHT20 has correctly uploaded a TwoWire class object reference
* @retval 2 Device is not found, please check if the connection is correct
* @retval 3 If the sensor init fails, please check if there is any problem with the sensor, you can call the reset function and re-initialize after restoring the sensor
*/
uint8_t begin();
/**
* @fn reset
* @brief Sensor soft reset, restore the sensor to the initial status.
* @return NONE
*/
void reset();
/**
* @fn startMeasurementReady
* @brief Start measurement and determine if it’s completed.
* @param crcEn Whether to enable check during measurement
* @n false Measure without check (by default)
* @n true Measure with check
* @return Whether the measurement is done
* @retval true If the measurement is completed, call a related function such as get* to obtain the measured data.
* @retval false If the measurement failed, the obtained data is the data of last measurement or the initial value 0 if the related function such as get* is called at this time.
*/
bool startMeasurementReady(bool crcEn = false);
/**
* @fn getTemperature_F
* @brief Get ambient temperature, unit: Fahrenheit (F).
* @return Temperature in F
* @note AHT20 can't directly get the temp in F, the temp in F is calculated according to the algorithm: F = C x 1.8 + 32
* @n Users must call the startMeasurementReady function once to start the measurement before calling this function so as to get the real-time measured data,
* @n otherwise what they obtained is the initial data or the data of last measurement.
*/
float getTemperature_F();
/**
* @fn getTemperature_C
* @brief Get ambient temperature, unit: Celsius (℃).
* @return Temperature in ℃, it's normal data within the range of -40-85℃, otherwise it's wrong data
* @note Users must call the startMeasurementReady function once to start the measurement before calling this function so as to get the real-time measured data,
* @n otherwise what they obtained is the initial data or the data of last measurement.
*/
float getTemperature_C();
/**
* @fn getHumidity_RH
* @brief Get ambient relative humidity, unit: %RH.
* @return Relative humidity, range 0-100
* @note Users must call the startMeasurementReady function once to start the measurement before calling this function so as to get the real-time measured data,
* @n otherwise what they obtained is the initial data or the data of last measurement
*/
float getHumidity_RH();
More Documents
SEN0528-Circuit Diagram SCH.pdf
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.