Display temperature and humidity data with HTS221

Updated on 3 September 2021
dev board Arduino Nano 33 BLE Sense
firmware Arduino
chip HTS221
sensor temperature
sensor humidity
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Pre-requisites

Try these simpler or similar examples:

Buy the components

Code

Download code nano33-ble-sense-temperature-humidity.ino
#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

Description

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

Install the dependancy:

arduino-cli lib install Arduino_HTS221

References