Fermion: AHT20 Temperature and Humidity Sensor Arduino Wiki - DFRobot

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

Applications

Pinout

Pin Function Description
VCC + Power Supply: DC 2V~5V
GND - --
SCL I2C Clock Line --
SDA I2C Data Line --

Specification

Module Parameters

AHT20 Chip Parameters

Relative Humidity

Temperature

Dimension Diagram

Tutorial

Hardware Requirement

Software Requirement

Connection Diagram

UNO Board: 3V3 - connect to - AHT20:VCC
UNO Board: GND - connect to - AHT20:GND
UNO Board: SCL - connect to - AHT20:SCL
UNO Board: SDA - connect to - AHT20:SDA

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);
  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(/* crcEn = */true)){
    Serial.print(aht20.getTemperature_C());
    Serial.print(" C, ");
    // Get temp in Fahrenheit (F)
    Serial.print(aht20.getTemperature_F());
    Serial.print(" F\t");
    Serial.print(aht20.getHumidity_RH());
    Serial.println(" %RH");
    delay(5000);
  }
}

Result

As shown in the figure below, the temperature values in ℃ and ℉, and humidity values are displayed in the serial monitor.

API Function

 /**
   * @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

SEN0527_2D Dimensions_PDF.pdf

SEN0527_2D Dimensions_CAD.rar

SEN0527_3DSTP.rar

SEN0527-Circuit Diagram SCH.pdf

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

DFshopping_car1.png Get Fermion: AHT20 Temperature and Humidity Sensor from DFRobot Store or DFRobot Distributor.

Turn to the Top