Temp RH Module

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

Overall Info

Turta Temp & RH Module is temperature and relative humidity sensing add-on board. It carries ST HTS221 digital sensor. HTS221 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.



Module Connections

  • I2C: SCL and SDA.

  • INT: Data ready out.

  • POWER: +3.3V and GND.


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.


To get maximum performance from your hardware, please make sure you'll meet the following requirements.


Temp & RH Module is an add-in board for Turta Modular System. You'll need a compatible host device for your module. The following devices support Temp & RH Module:

  • Turta IoT Node - ESP32

The temperature sensor is sensitive to surrounding temperatures. It is recommended to avoid overloading host device to keep it cool. So please ensure air flow to the sensor, e.g., open enough ventilation holes for the sensor and the host board. Besides, relative humidity is being calculated by using temperature reading. So, the temperature is also affecting relative humidity readings.


For ESP32 based systems, we're currently supporting Arduino core. Please make sure you've installed the following:

  • Arduino IDE.

  • ESP32 Hardware libraries for the Arduino IDE.

  • Python for the compilation of Arduino projects.

  • Drivers for your host device, e.g., USB Virtual Serial Port driver.


You'll need to install a library to make Arduino IDE support the sensor. This library includes drivers for the HTS221 sensor and sample code for you to jumpstart your project.


Please download the library archive from https://github.com/Turta-io/Modular

Then, copy its contents to your Arduino Libraries folder.

You can find the Arduino Libraries folder inside your Arduino sketch directory. It is generally located inside the My Documents folder.


The library comes with included samples. There is no need to download additional files for the examples.

Source Code

The hardware, its drivers and the sample code are open source. You can use them under the terms of the MIT license. Please feel free to customize and prototype them for your projects.

Arduino Library

Turta_TempRH_Module 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_Module.h>

Then, create an instance of the Turta_TempRH_Module class.

Turta_TempRH_Module th

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


To initialize the sensor, call the begin method.


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.


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

Temp RH

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 IoT_Node_TempRH sketch from the examples menu.

  2. Select Turta IoT Node 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

#include <Turta_TempRH_Module.h>
// Create Temperature & RH Sensor instance.
Turta_TempRH_Module th;
void setup() {
// Initialize Temperature & RH Sensor.
// Configure serial port.
void loop() {
// Read temperature.
double temperature = th.readTemperature();
Serial.print("Temperature: ");
// Read relative humidity.
double humidity = th.readHumidity();
Serial.print("Humidity: ");
// Print an empty line.
// Delay 1000ms = 1 seconds.


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.


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

Problem: You're reading NaN instead of sensor data. Cause: The host device does not communicate with the sensor over the I2C protocol. There is a software bug on the ESP32 Arduino hardware library which prevents I2C communication. Solution: Please update the ESP32 hardware library.

Problem: Temperature reading is above, and humidity reading is below from it should be. Cause: ESP32's CPU can reach up to 240MHz, which heats itself and surroundings. Solution: For temperature and humidity reading applications, it would be better first to read the sensor data, then run the other tasks. If you're making just a temperature & humidity sensing device, you may wish to DeepSleep the host device while it is idle.

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 module at 100 °C for 15 minutes to make moisture escape from the sensor's measuring hole.

Problem: Sensor readings are not accurate after inserting the sensor to the slot, while the application is running. Cause: The sensor library reads the calibration coefficients at the beginning of the application. If you insert the sensor module after the application is started, the library does not get the calibration coefficients and return inaccurate readings. Solution: Please press the reset button on the host board, or upload the application again while the sensor module is in the sensor slot.