Skip to content

Arduino Guide ​

Library Installation ​

  1. Launch Arduino IDE.
  2. Open the Library Manager: Sketch ➔ Include Library ➔ Manage Libraries....
  3. Search for Sensirion I2C SHT3X in the Filter your search... field, then click Install.

Wiring Diagram ​

The wiring diagram will be added here.

Example ​

Single-Shot Temperature and Humidity Measurement ​

In single-shot mode, the controller sends a measurement command and the sensor takes one reading. This lets you read data as needed with lower power consumption.

cpp
#include <Arduino.h>
#include <SensirionI2cSht3x.h>
#include <Wire.h>

SensirionI2cSht3x sensor;

static char errorMessage[64];
static int16_t error;

void setup() {

    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }
    Wire.begin();
    sensor.begin(Wire, SHT30_I2C_ADDR_44);

    sensor.stopMeasurement();
    delay(1);
    sensor.softReset();
    delay(100);
    uint16_t aStatusRegister = 0u;
    error = sensor.readStatusRegister(aStatusRegister);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute readStatusRegister(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
    Serial.print("aStatusRegister: ");
    Serial.print(aStatusRegister);
    Serial.println();
}

void loop() {

    float aTemperature = 0.0;
    float aHumidity = 0.0;
    error = sensor.measureSingleShot(REPEATABILITY_MEDIUM, false, aTemperature,
                                     aHumidity);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute measureSingleShot(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
    Serial.print("aTemperature: ");
    Serial.print(aTemperature);
    Serial.print("\t");
    Serial.print("aHumidity: ");
    Serial.print(aHumidity);
    Serial.println();
}

Result: The measured temperature and humidity are printed to the serial port.

Periodic Temperature and Humidity Measurement ​

In periodic mode, the sensor takes measurements automatically at the configured sampling rate.

cpp
#include <Arduino.h>
#include <SensirionI2cSht3x.h>
#include <Wire.h>

SensirionI2cSht3x sensor;

static char errorMessage[64];
static int16_t error;

void setup() {

    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }
    Wire.begin();
    sensor.begin(Wire, SHT30_I2C_ADDR_44);

    sensor.stopMeasurement();
    delay(1);
    sensor.softReset();
    delay(100);
    uint16_t aStatusRegister = 0u;
    error = sensor.readStatusRegister(aStatusRegister);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute readStatusRegister(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
    Serial.print("aStatusRegister: ");
    Serial.print(aStatusRegister);
    Serial.println();
    error = sensor.startPeriodicMeasurement(REPEATABILITY_MEDIUM,
                                            MPS_ONE_PER_SECOND);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute startPeriodicMeasurement(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
}

void loop() {

    float aTemperature = 0.0;
    float aHumidity = 0.0;
    error = sensor.blockingReadMeasurement(aTemperature, aHumidity);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute blockingReadMeasurement(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
    Serial.print("aTemperature: ");
    Serial.print(aTemperature);
    Serial.print("\t");
    Serial.print("aHumidity: ");
    Serial.print(aHumidity);
    Serial.println();
}

Result: For the first 10 seconds, the serial port prints temperature and humidity readings from periodic mode. After 10 seconds, the sensor exits periodic mode, enters single-shot mode, and prints the readings obtained in single-shot mode.