Display temperature and humidity data with HTS221

arduino nano 33 ble sense temperature humidity HTS221

Pre-requisites

Display temperature and humidity values with sensor HTS221 on Arduino Nano 33 BLE Sense board.

Install the dependancy:

arduino-cli lib install Arduino_HTS221

Code

Download code
#include <Arduino_HTS221.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) {}

  if (!HTS.begin()) {
    Serial.println("Failed to initialize humidity temperature sensor!");
    while (1) {}
  }
}

void loop() {
  float temperature = HTS.readTemperature();
  float humidity = HTS.readHumidity();

  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println("°C");

  Serial.print("Humidity = ");
  Serial.print(humidity);
  Serial.println("%");

  Serial.println();

  delay(1000);
}

Serial console

Serial output from the firmware.

Display temperature and humidity data with HTS221 serial console

References