Use HTU21D Temperature & Humidity Sensor


  • Ameba x 1
  • HTU21D Sensor x 1
  • 4.7KΩ Resistancex 1


HTU21D is a sensor provides digital outputs for humidity and temperature. The temperature operating range from -40℃ to 105℃ and the humidity operating range from 10%RH to 95%RH with HTU21D±2%RH. And it uses I2C interface to communicate with Ameba.

Download HTU21DF Library

Library installation can refer to the manual from Arduino official website and then add the library (.zip) to Ameba:

HTU21D needs to connect to Pull High4.7KΩ resistance and RTL8195 Wiring is as follows:


RTL8710 Wiring is as follows:


Open “File” -> “Examples” -> “Adafruit HTU21DF Library” -> “HTU21DFtest”, compile and upload to Ameba. Then, click “Reset” button to reboot and you can see the outputs on Serial Monitor as follows:


Code Reference

This example is simple. First, declare Adafruit_HTU21DF class.

Adafruit_HTU21DF htu = Adafruit_HTU21DF();

Next, use htu.begin() in setup() to check if the HTU21DF starts up successfully.

if (!htu.begin()) {
    Serial.println("Couldn't find sensor!");
    while (1);

Now you can read the temperature and humidity data via readTemperature() and readHumidity() respectively from htu in loop().

void loop() {
  Serial.print("Temp: "); 
  Serial.print("\t\tHum: "); 
Please confirm that QQ communication software is installed