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);
}

Makefile

BOARD?=arduino:mbed:nano33ble
PORT?=/dev/cu.usbmodem14*
BUILD=build

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -r build

Serial console

Serial output from the firmware.

Display temperature and humidity data with HTS221 serial console

References