SHT31 / SHT31-D / GY-SHT31 / SI7021 Temperature and Humidity Sensor

View on Amazon
Overview
About SHT31 / SHT31-D / GY-SHT31 / SI7021 Temperature and Humidity Sensor
The SHT31, SHT31-D, GY-SHT31, and SI7021 sensors share a similar architecture, delivering high-accuracy temperature and humidity measurements. An improvement over the SHT30, the SHT31 series offers enhanced reliability and performance, making it ideal for HVAC systems, environmental monitoring, data logging, and IoT applications.
⚡ Key Features
- Improved Accuracy & Stability – More precise than previous models.
- I²C Communication – Seamless integration with ESP32, Arduino, and microcontrollers.
- Enhanced Performance – Faster response time and better long-term reliability.
- Versatile Applications – Used in industrial, smart home, and scientific monitoring systems.
With its higher precision and durability, the SHT31 series is a great choice for demanding climate monitoring applications. 🚀
For applications demanding even higher precision, faster response times, or specialized features, consider the SHT35 sensor, which provides superior performance for demanding environments.
Get Your SHT31 / SHT31-D / GY-SHT31 / SI7021
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
SHT31 / SHT31-D / GY-SHT31 / SI7021 Specifications
Complete technical specification details for SHT31 / SHT31-D / GY-SHT31 / SI7021 Temperature and Humidity Sensor
📊 Technical Parameters
SHT31 / SHT31-D / GY-SHT31 / SI7021 Pinout
The SHT31 uses standard I²C communication with 4 pins, offering high accuracy with wide voltage range.
Visual Pinout Diagram

Pin Types
Quick Tips
Standard I²C interface for easy integration,📡 Default I²C address is 0x44 or 0x45 (configurable)
Exceptional accuracy: ±0.2°C temp, ±2% humidity,⚡ Wide voltage range (2.15V-5.5V) for flexibility
Enhanced version of SHT30 with better performance
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VDD | Power | Power supply input (2.15V to 5.5V) | Wide voltage range for various applications |
2 GND | Power | Ground connection | Connect to ESP32 ground |
3 SDA | Communication | I²C data line | Bidirectional data communication |
4 SCL | Communication | I²C clock line | Clock signal from master device |
Wiring SHT31 / SHT31-D / GY-SHT31 / SI7021 to ESP32
Connect the SHT31 using standard I²C interface for professional-grade measurements.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| SHT31 / SHT31-D / GY-SHT31 / SI7021 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VDD Required | 3.3V | Power supply (2.15V to 5.5V supported) | |
2 GND Required | GND | Ground connection | |
3 SDA Required | GPIO21 | I²C data line (default SDA) | |
4 SCL Required | GPIO22 | I²C clock line (default SCL) |
GPIO21/22 are default I²C pins on ESP32
I²C address is 0x44 or 0x45 (check your module)
Add 10kΩ pull-up resistors on SDA/SCL if needed
Can share I²C bus with other devices
SHT31 / SHT31-D / GY-SHT31 / SI7021 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The SHT31-D sensor functions correctly for a few minutes but then ceases to provide readings. The serial monitor may display repeated messages such as Failed to read temperature and Failed to read humidity.
Possible causes include unstable connections, power supply issues, or sensor malfunction.
Solution: Ensure all connections are secure and that the sensor is receiving a stable power supply. Consider testing with different wires or a breadboard to rule out connection issues. If the problem persists, the sensor may need to be power-cycled or replaced.
Issue: When measuring negative temperatures, the SHT31 sensor returns incorrect values, such as 42949672.0°C, instead of the expected negative readings.
Possible causes include limitations of the specific sensor model or issues with the data conversion method used in the code.
Solution: Verify that the sensor model supports the desired temperature range. If the sensor is appropriate, review the data conversion logic in the code to ensure it correctly handles negative values.
Issue: Attempting to compile code results in the error message: 'Wire1' was not declared in this scope.
Possible causes include the use of code intended for a different microcontroller that supports multiple I2C interfaces, while the current microcontroller does not.
Solution: Modify the code to use the appropriate I2C interface for your microcontroller. For instance, replace instances of Wire1 with Wire if only one I2C interface is available.
Issue: The SHT31 sensor is not detected at the expected I2C address 0x44 or 0x45, leading to communication failures.
Possible causes include incorrect wiring of the address pin or improper sensor initialization.
Solution: Verify the connection of the address pin (ADDR) to set the desired I2C address: connecting to GND sets the address to 0x44, while connecting to VCC sets it to 0x45. Ensure the code matches the configured address and that the sensor is properly initialized.
Debugging Tips
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.
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
SHT31 / SHT31-D / GY-SHT31 / SI7021 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
if (!sht31.begin(0x44)) { // Set to 0x45 for alternate I2C address
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
}
void loop() {
float t = sht31.readTemperature();
float h = sht31.readHumidity();
if (!isnan(t) && !isnan(h)) { // Check if readings are valid
Serial.print("Temp *C = "); Serial.print(t); Serial.print(" ");
Serial.print("Hum. % = "); Serial.println(h);
} else {
Serial.println("Failed to read from SHT31 sensor");
}
delay(1000);
}#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c.h"
#define I2C_MASTER_SCL_IO 22 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 21 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C master I2C port number */
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
#define SHT31_SENSOR_ADDR 0x44 /*!< SHT31 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_err_t err = i2c_param_config(I2C_MASTER_NUM, &conf);
if (err != ESP_OK) {
return err;
}
return i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0);
}
void read_sht31_sensor() {
uint8_t data[6];
i2c_master_write_read_device(I2C_MASTER_NUM, SHT31_SENSOR_ADDR, NULL, 0, data, sizeof(data), 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_sht31_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}sensor:
- platform: sht3x
address: 0x44
temperature:
name: "Room Temperature"
humidity:
name: "Room Humidity"
update_interval: 60splatformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit SHT31 Library @ ^2.0.0
monitor_speed = 115200main.cpp
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
if (!sht31.begin(0x44)) { // Default I2C address for SHT31
Serial.println("Couldn't find SHT31 sensor!");
while (1) delay(1);
}
}
void loop() {
float temperature = sht31.readTemperature();
float humidity = sht31.readHumidity();
if (!isnan(temperature) && !isnan(humidity)) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
Serial.println("Failed to read from SHT31 sensor");
}
delay(2000);
}from machine import I2C, Pin
from time import sleep
import sht31
# Initialize I2C interface
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Initialize the SHT31 sensor
sensor = sht31.SHT31(i2c, addr=0x44)
print("SHT31 Sensor Example")
while True:
try:
temperature, humidity = sensor.measure()
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
except Exception as e:
print("Error reading from SHT31: ", e)
sleep(2)Wrapping Up SHT31 / SHT31-D / GY-SHT31 / SI7021
The ESP32 SHT31 / SHT31-D / GY-SHT31 / SI7021 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.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the SHT31 / SHT31-D / GY-SHT31 / SI7021 into your ESP32 project and bring your ideas to life!








