ESP32 SHT41 / SHT41-D / GY-SHT41-D Temperature and Humidity Sensor Pinout
Overview
The SHT41 sensor is part of Sensirion's SHT4x series and offers high-accuracy temperature and humidity measurements. It is factory calibrated and provides digital I2C output for easy integration. The SHT41 is a robust and reliable solution for applications requiring precise environmental monitoring.
About SHT41 / SHT41-D / GY-SHT41-D Temperature and Humidity Sensor
The SHT41, SHT41-D, and GY-SHT41-D, developed by Sensirion, are high-accuracy digital sensors from the SHT4x series. They provide fully calibrated, linearized, and temperature-compensated digital outputs, making them ideal for demanding applications such as environmental monitoring, industrial automation, and IoT devices.
⚡ Key Features
- Exceptional Accuracy – Ensures precise temperature and humidity measurements.
- Pre-Calibrated & Temperature-Compensated – Ready for immediate, reliable use.
- I²C Communication – Easily integrates with ESP32, Arduino, and embedded systems.
- Industrial-Grade Reliability – Ideal for HVAC, weather monitoring, and automation.
With their high precision and stability, the SHT41 series sensors are perfect for advanced climate monitoring applications. 🚀
Where to Buy SHT41 / SHT41-D / GY-SHT41-D Temperature and Humidity Sensor
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
SHT41 / SHT41-D / GY-SHT41-D Datasheet and Technical Specifications
SHT41 / SHT41-D / GY-SHT41-D Pinout Diagram
The SHT41 pinout is as follows:
- VDD: Power supply voltage (2.4V to 5.5V).
- GND: Ground.
- SDA: Serial Data Line for I2C communication.
- SCL: Serial Clock Line for I2C communication.
SHT41 / SHT41-D / GY-SHT41-D Wiring with ESP32

- Connect VDD to the 3.3V pin on the ESP32.
- Connect GND to the ground (GND) of the ESP32.
- Connect SDA to the ESP32's GPIO21 (default I2C data pin).
- Connect SCL to the ESP32's GPIO22 (default I2C clock pin).
- Place pull-up resistors (10kΩ) between SDA and VDD, and SCL and VDD, to ensure reliable communication.
SHT41 / SHT41-D / GY-SHT41-D Troubleshooting Guide
Common Issues
🔄 Intermittent Sensor Functionality on ESP32
Issue: The SHT41 sensor exhibits unreliable behavior when connected to an ESP32. Some sensors function without issues, while others intermittently stop working or cause the ESP32 to freeze. The error message observed is: Recovery failed: SCL is held LOW on the i2c.
Possible causes include insufficient pull-up resistors on the I2C lines, leading to communication instability.
Solution: Ensure that appropriate pull-up resistors are present on the SDA and SCL lines. If the sensor board lacks built-in pull-ups, add external resistors (typically 4.7kΩ to 10kΩ) to stabilize the I2C communication. Additionally, verify that the power supply is stable and that all connections are secure. (forum.arduino.cc)
🔥 Inaccurate Temperature Readings Due to Self-Heating
Issue: The SHT41 sensor reports temperature readings higher than the actual ambient temperature. This discrepancy is often due to self-heating caused by nearby components on the PCB, such as microcontrollers, voltage regulators, or LEDs.
Possible causes include heat generated by adjacent components affecting the sensor's measurements.
Solution: To minimize self-heating effects, consider the following approaches:
- Isolate the sensor from heat-generating components by placing it on a separate PCB or using physical barriers.
- Implement duty-cycling in your code to reduce the sensor's active time, thereby decreasing heat accumulation.
- Ensure adequate ventilation around the sensor to dissipate heat effectively.
⚠️ Communication Error: OSError: [Errno 19] ENODEV
Issue: When attempting to read data from the SHT41 sensor using an ESP32 with MicroPython, the following error occurs: OSError: [Errno 19] ENODEV. This error arises during the I2C read operation, despite the sensor being detected at address 0x44 during scanning.
Possible causes include improper I2C communication sequences or timing issues.
Solution: Implement a soft reset of the sensor before initiating data reads. This can be achieved by sending the appropriate reset command as specified in the sensor's datasheet. Additionally, ensure that the I2C communication follows the correct sequence and adheres to the timing requirements outlined by the manufacturer. (github.com)
❌ Incorrect Readings on SHT4x Smart Gadget
Issue: When using the SHT4x Smart Gadget to read data from an external SHT41-AD1B sensor, the display shows values like 3.0 for temperature and 0.1 for humidity, which are incorrect.
Possible causes include improper connection or configuration of the external sensor.
Solution: Verify that the external sensor is correctly connected to the Smart Gadget, ensuring proper alignment and secure connections. Consult the Smart Gadget's user manual to confirm that it supports the specific sensor model and that any necessary configuration settings are correctly applied. (forum.digikey.com)
Debugging Tips
🔍 Serial Monitor
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
⚡ Voltage Checks
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
SHT41 / SHT41-D / GY-SHT41-D Code Examples
Arduino Example
#include <Wire.h>
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4;
void setup() {
Serial.begin(115200);
if (!sht4.begin()) {
Serial.println("Couldn't find SHT41 sensor!");
while (1) delay(10);
}
sht4.setPrecision(SHT4X_HIGH_PRECISION);
Serial.println("SHT41 initialized");
}
void loop() {
sensors_event_t humidity, temp;
if (!sht4.getEvent(&humidity, &temp)) {
Serial.println("Failed to read sensor data");
return;
}
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" °C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println(" %");
delay(2000);
}ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c.h"
#define I2C_MASTER_SCL_IO 22 /!< GPIO number for I2C master clock /
#define I2C_MASTER_SDA_IO 21 /!< GPIO number for I2C master data /
#define I2C_MASTER_NUM I2C_NUM_0 /!< I2C master port /
#define I2C_MASTER_FREQ_HZ 100000 /!< I2C master clock frequency /
#define SHT41_SENSOR_ADDR 0x44 /!< SHT41 I2C address /
static esp_err_t i2c_master_init(void) {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));
return i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0);
}
void read_sht41_sensor() {
uint8_t data[6];
uint8_t cmd[] = {0xFD}; // High precision measurement command
i2c_master_write_to_device(I2C_MASTER_NUM, SHT41_SENSOR_ADDR, cmd, 1, pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(10));
i2c_master_read_from_device(I2C_MASTER_NUM, SHT41_SENSOR_ADDR, data, 6, pdMS_TO_TICKS(1000));
uint16_t temp_raw = (data[0] << 8) | data[1];
uint16_t hum_raw = (data[3] << 8) | data[4];
float temperature = -45 + 175 ((float)temp_raw / 65535.0);
float humidity = 100 ((float)hum_raw / 65535.0);
printf("Temperature: %.2f °C, Humidity: %.2f %%\n", temperature, humidity);
}
void app_main() {
ESP_ERROR_CHECK(i2c_master_init());
while (1) {
read_sht41_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}ESPHome Example
sensor:
- platform: sht4x
address: 0x44
temperature:
name: "Room Temperature"
humidity:
name: "Room Humidity"
update_interval: 60ssht4x platform. It configures the sensor to read and update temperature and humidity values every 60 seconds, with user-friendly names like 'Room Temperature' and 'Room Humidity.'PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit SHT4x Library @ ^1.0.0
monitor_speed = 115200PlatformIO Example Code
#include <Wire.h>
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4;
void setup() {
Serial.begin(115200);
if (!sht4.begin()) {
Serial.println("Couldn't find SHT41 sensor!");
while (1) delay(10);
}
sht4.setPrecision(SHT4X_HIGH_PRECISION);
Serial.println("SHT41 initialized.");
}
void loop() {
sensors_event_t temp, humidity;
if (!sht4.getEvent(&humidity, &temp)) {
Serial.println("Failed to read sensor data");
return;
}
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
delay(2000);
}MicroPython Example
from machine import I2C, Pin
from time import sleep
# Initialize I2C interface
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# SHT41 I2C address
SHT41_ADDR = 0x44
# Command for high-precision measurement
MEASURE_CMD = b'\xFD'
while True:
try:
i2c.writeto(SHT41_ADDR, MEASURE_CMD)
sleep(0.01) # Wait for measurement to complete
data = i2c.readfrom(SHT41_ADDR, 6)
raw_temp = (data[0] << 8) | data[1]
raw_hum = (data[3] << 8) | data[4]
temperature = -45 + 175 (raw_temp / 65535.0)
humidity = 100 (raw_hum / 65535.0)
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
except Exception as e:
print("Error reading SHT41: ", e)
sleep(2)Conclusion
The ESP32 SHT41 / SHT41-D / GY-SHT41-D Temperature and Humidity Sensor is a powerful environment sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.









