← Back to list

Use an SHT41 Environment Sensor with an ESP32-H2 Super Mini Development Board and get indoor…

This tutorial is part of a series of articles about the small ESP32-H2 Super Mini (“SM”) development board. I will explain how to control…

AndroidCrypto · 2026-02-08 12:31 · 5 claps · 4.1 min read
#esp32-h2 #sht41 #environment-sensor #arduino #i2c
Open on Medium ↗
Wiki topics: 📟 · Gadgets & IoT

Use an SHT41 Environment Sensor with an ESP32-H2 Super Mini Development Board and get indoor temperature and humidity

This tutorial is part of a series of articles about the small **ESP32-H2 Super Mini (“SM”) development board. I will explain how to control an external SHT41 environment sensor so that you can use it in your projects. I store all relevant settings and methods in a separate header file** so that I can add them modularly as needed.

SHT41 sensor readings on an SSD1306 OLED display

SHT41 sensor readings on an SSD1306 OLED display

For this tutorial, I have chosen the SHT41 environmental sensor, manufactured by Sensirion, which is designed to reliably measure the temperature and humidity in a room. Please note that all sensors should be calibrated before being used in a device. My sensor reported elevated temperature and humidity readings, which can usually be balanced by simple addition or subtraction. But often it’s only about measuring a change or triggering a reaction at a self-defined threshold—then absolute accuracy is not so crucial.

These modules are available on AliExpress for approximately 2 euros. Please pay attention to the supply voltage (we require 3.3 volts) and the I2C interface. The advantage of the I2C interface is that several different devices can be connected to the two-pin bus, as they have different addresses.

Integration of the SHT41 header file

In the main sketch, you include this header file as follows.

#include "SHT41_SENSOR.H"

The header section defines an entry that can later be referenced in the program to include or omit a part of the program (“preprocessor directives”).

For communication between our ESP32-H2 device and the sensor, I use the **Adafruit SHT4x library** in version 1.0.5.

The complete header section looks like this:

#ifndef IS_SHT41_SENSOR
#define IS_SHT41_SENSOR
#endif
#define SHT41_I2C_SDA_PIN 5
#define SHT41_I2C_SCL_PIN 4
#include
float temperature = -99;
float humidity = -99;
float pressure = -99;
float altitude = -99;

You might be surprised that we are providing variables here that are not provided by our sensor. However, it’s possible that you might soon replace the sensor with, for example, a BME280 sensor, and then you won’t need to change your actual program, as all the variables will already be available.

Setup of the sensor

The sensor is wired to an I2C bus, and calling this method will set up the sensor:

void setupSht41(bool skipWire = false);

The parameter “skipWire” is important if you add more than one device on the same I2C bus. To avoid multiple “Wire.begin(…)” commands in this case, you set the parameter to true for all subsequent “setupXXX(true)” calls.

In addition to connecting the sensor to the I2C interface, two settings are also made that influence the sensor quality, namely the use of a built-in heater (setting: no heater) and the precision (setting: HIGH precision).

SHT41 sensor setup on an SSD1306 OLED display

SHT41 sensor setup on an SSD1306 OLED display

Querying and printing the measured values

For both tasks, I provide methods that are called as follows:

void getSht41Values() {...}
void printSht41Values() {...}

This is a sample output on the Serial Monitor:

ESP32 H2 Super Mini External SHT41 Environment Sensor and SSD1306 OLED display V01
CPU frequency before setting: 96 MHz
CPU frequency after  setting: 48 MHz
Wire1.begin was success
Init SHT41 SUCC
Found SHT4x sensor
Serial number 0x113D39BE
High precision
No heater
The SHT41 sensor is set up
The SSD1306 OLED display is set up
SHT41 Temperature: 21.49 C Humidity: 45.8 %rH Pressure: n.a. Altitude: n/a
SHT41 Temperature: 21.49 C Humidity: 45.8 %rH Pressure: n.a. Altitude: n/a

Behavior of the sensor at different CPU frequencies

When you select a board in Arduino Tools, you define certain parameters, including the processor speed. However, with the ESP32-H2 Dev Module, there is no way (bug?) to adjust the speed via the Arduino IDE interface.

There is a simple reason for lowering the processor speed: a slower-running processor consumes less power and is therefore a valid option for battery-powered devices to increase runtime.

Therefore, I have included a feature in the test program to reduce the processor speed from 96 MHz (default) to the lowest possible speed of 48 MHz. This is done by enabling (uncommenting) this line in the header:

#define TEST_48MHZ_CPU_FREQUENCY

The result is positive; the program works perfectly even with a CPU speed of 48 MHz.

Sensor behavior in deep sleep

Whenever you write a program for a microcontroller that will later be powered by a battery, you should keep a close eye on the power consumption of each individual component. Even a small continuous current draw from an external component can negate all other power-saving measures and lead to poor battery life. The library I use indicates that the sensor automatically enters sleep mode immediately after new measurements are provided and does not need to be explicitly instructed to do so.

Test program

The test program tests all the functions of the helper file. To ensure the output is displayed in the “Serial Monitor”, you must enable the parameter “USB CDC on boot enabled” during compilation and upload.

If you want to see the measured values ​​even without the Serial Monitor, I recommend connecting an OLED to the ESP32-H2 (tutorial), and there is an extended version of the SHT41 sketch in the repository for display output.

Source code of the app

You find the complete code of the app in my **GitHub repository**. Since this is a series of articles, all sketches in this series are compiled in one repository. In this repository you will find zip files with all relevant libraries used in this sketch, in case they are no longer available online.

Back to the overview tutorial “**ESP32-H2 Super Mini — Small form factor, big impact (LoRa, ePaper, environment sensor, and battery powered and monitored)**”

Happy coding !


메타데이터
post_id
4404c4ffa57f
slug
use-an-sht41-environment-sensor-with-an-esp32-h2-super-mini-development-board-and-get-indoor-4404c4ffa57f
url
https://medium.com/@androidcrypto/use-an-sht41-environment-sensor-with-an-esp32-h2-super-mini-development-board-and-get-indoor-4404c4ffa57f
canonical_url
https://medium.com/@androidcrypto/use-an-sht41-environment-sensor-with-an-esp32-h2-super-mini-development-board-and-get-indoor-4404c4ffa57f
author_url
https://medium.com/@androidcrypto
status
ok
fetched_at
2026-06-11 15:16:29