3.10 Temperature and Humidity Sensor

3.10.1 Overview

AHT20 temperature and humidity sensor adopts I2C interface and 20Bit ADC, and its operating voltage is 2V-5V. It features small volume, stable performance and high precision (accuracy: temperature ±0.3℃, humidity ±2%RH). So it is widely used in smart home, consumer electronics, medical and automotive. The sensor is stable and can work in harsh environments.

3.10.2 Schematic Diagram

image-20240701144311341

ATH20 temperature and humidity sensor transmits data via I2C interface, and it works according to resistive and capacitive technology. It detects the temperature because the material’s conductivity changes with temperature, and it reflects humidity through the change in the capacitance value. The temperature measurement range is -40 ° C to +85 ° C with accuracy of ±0.3 ° C, and the humidity range is 0% ~ 100%RH ±2%RH. Besides, it features high accuracy, high reliability and long-term stability. With I2C protocol, ATH20 provides real-time and accurate temperature and humidity data under a variety of environmental conditions.

3.10.3 Code Blocks

image-20240702083642783

This block reads reads the temperature and humidity values. But it only reads one of them at once.

3.10.4 Test Code

3.10.4.1 Build Code

There are two ways to upload the code: directly open the code file we provide; or manually build blocks.

Directly open the code file we provide:

  1. Click and choose Load from your computer

  1. We have already downloaded the codes on computer desktop, so open the file and choose 3-10-aht20.sb3

Manually build blocks:

  1. In events, find j1 block.

  2. In serial, find j12 block and set baud rate to 9600, and put it under j1.

  3. In control, drag j2.6-4-4-1-1

6-2

  1. In serial, put j13 in j2, and set to print “T: ” in no-warp mode.

  2. Add another image-20240701141959486 and set to no-warp

  3. In image-20240702084630903, put j14 into the printing box of j13 to read “Temperature”.

    6-10

  4. Duplicate 6-10 and change “T: ” into “ RH:”(the two spaces separates the two values to be output). Read “Humidity” value.

  5. Add a delay of 1S for better observing the results.

Complete Test Code

6-10-4-1-3

3.10.4.2 Test Result

After uploading code, the serial monitor prints temperature and humidity values and refreshes the results per second.

6-10