HTS221 Temp RH Sensor

This documentation includes installation guidelines and sample code for your hardware.

Overall Info

ST HTS221 is a temperature and relative humidity sensor. It includes a sensing element and a mixed signal ASIC to provide the measurement information through a digital serial interface. This sensor is factory calibrated, so there is no need for manual calibration.

Sensor Connections

  • SCL: D12.

  • SDA: D11.

  • DRDY INT: A0.

  • POWER: VCC (+3.3V) and GND.

Specifications

HTS221's technical specifications are as follows:

  • 0 to 100% relative humidity range.

  • Humidity accuracy: ± 3.5% rH, 20 to 80% rH (± 5% rH, 0 to 100% rH)

  • Operating temperature range: -40 to 120 °C

  • Temperature accuracy: ± 0.5 °C,15 to +40 °C

  • Factory calibrated.

Arduino Library

Turta_TempRH_Sensor library is responsible for initializing the sensor, reading calibration data and reading temperature and humidity values with respect to calibration data.

To use the library on Arduino IDE, add the following #include statement to the top of your sketch.

#include <Turta_TempRH_Sensor.h>

Then, create an instance of the Turta_TempRH_Sensor class.

Turta_TempRH_Sensor th

Now you're ready to access the library by calling the th instance.

Initialization

To initialize the sensor, call the begin method.

begin()

This method turns the sensor on and then reads the calibration coefficients to the memory.

Basic Members

Read Temperature

Returns the last measured temperature reading from the sensor.

double readTemperature()
  • Parameters

    • None

  • Returns

    • Double: Temperature

Read Humidity

Returns the last measured relative humidity reading from the sensor.

double readHumidity()
  • Parameters

    • None

  • Returns

    • Double: Relative humidity.

Advanced Members

HTS221 Sensor includes advanced functions, just like controlling its internal heater for humidity sensing. Heater control methods will be implemented in the next release.

Examples

You can open the example from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta MKR Sensor Shield > Temp RH Sensor. There is one example of this sensor.

Temperature Humidity

This application demonstrates temperature and humidity reading functions of the module. It uses Arduino IDE's Serial Monitor to display sensor readings.

To run the example:

  1. Open the Temperature Humidity sketch from the examples menu.

  2. Select your Arduino MKR series board from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

Temperature Humidity.ino
#include <Turta_TempRH_Sensor.h>

// Create Temperature & RH Sensor instance.
Turta_TempRH_Sensor th;

void setup() {
  // Initialize Temperature & RH Sensor.
  th.begin();

  // Configure serial port.
  Serial.begin(115200);
  delay(200);
}

void loop() {
  // Read temperature.
  double temperature = th.readTemperature();
  Serial.print("Temperature: ");
  Serial.println(temperature);

  // Read relative humidity.
  double humidity = th.readHumidity();
  Serial.print("Humidity: ");
  Serial.println(humidity);

  // Print an empty line.
  Serial.println("");

  // Delay 1000ms = 1 seconds.
  delay(1000);
}

Result

After the application is uploaded to the device, it writes current readings to the Serial Monitor each second. The example output should be like this:

Temperature: 24.04
Humidity: 63.67

Temperature: 24.07
Humidity: 63.65

Temperature: 24.09
Humidity: 63.63

The application runs forever until you clear it from memory.

Troubleshooting

If you're experiencing difficulties while working with your device, please try the following steps.

Problem: Humidity reading is much higher than it should be. Cause: In some cases, moisture does not escape from the sensor quickly. Solution: Please run the example application for a few hours and observe if the humidity level is decreasing. If not, you can bake the sensor shield at 100 °C for 15 minutes to make moisture escape from the sensor's measuring hole.

Last updated