Reference
Last revision 2025/12/18
Library
Download and install the DFRobot_AHT20 Library. (About how to install the library?)
Communication Protocol Description
- Communication Protocol: I2C
- I2C Address: 0x38
- I2C Clock Line: SCL Pin
- I2C Data Line: SDA Pin
API Description
/**
* @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();
Other Supplementary Information
Was this article helpful?
