SHT31 GY-SHT31-D I2C Temperature Humidity Sensor — ESP32 + OLED Examples

SHT31 GY-SHT31-D I²C Digital Temperature & Humidity Sensor — Alternative to BME280

Accurate temperature & humidity sensor on a compact I²C breakout (GY-SHT31-D). Perfect for ESP32/ESP8266/Raspberry Pi projects. Ready-to-use ESPHome and Arduino examples show the SHT31 connected to an ESP32 with an SSD1306 OLED display.

Condition: New Interface: I²C (SDA / SCL) Supply: 3.3V (check module) Sensor: SHT31

Highlights

  • High-accuracy SHT31 temperature & humidity sensing
  • Simple I²C interface — quick hookup to ESP32/ESP8266/RPi
  • Small, mountable breakout board
  • Great low-cost alternative to BME280 when pressure is not required

What’s Included

Specifications

SensorSHT31
InterfaceI²C (SDA, SCL)
Voltage3.3V (some breakouts support 5V VCC) — check module
Accuracy±0.3°C (typ) temperature, ±2% RH (typ) humidity
Operating RangeTemperature: −40…125°C; Humidity: 0–100% RH
PackageGY-SHT31-D breakout board
ConditionNew

Wiring — ESP32 with SSD1306 OLED (I²C)

Typical wiring for an ESP32 (I²C):

Confirm your breakout VCC voltage. Many SHT31 modules are 3.3V; some breakouts accept 5V on VCC but still use 3.3V logic. Always connect common ground and avoid powering sensors from different floating supplies.

Wiring diagram: ESP32 to SHT31 and SSD1306 OLED

Possible Uses

  • Home Environmental Monitoring
    Room temperature & humidity display, HVAC feedback, baby room comfort monitoring.
  • Greenhouse & Hydroponics
    Accurate humidity monitoring for plant health and irrigation control.
  • Weather Stations
    Temperature & humidity node for multi-sensor stations (pair with rain/wind sensors).
  • IoT & Home Automation
    ESPHome node feeding Home Assistant, MQTT sensor for automations and logging.
  • Industrial & Lab Monitoring
    Non-pressurized environmental monitoring where high accuracy is required.
  • Data Logging & Education
    Workshops, student projects, and research where temperature/humidity trends matter.
  • HVAC Calibration
    Portable reference sensor for quick checks and comparisons to other sensors.
  • Appliance Monitoring
    Monitor humidity-sensitive appliances (dry cabinets, incubators, storage).

ESPHome Example — ESP32 + SHT31 + SSD1306

Click to expand — ESPHome YAML (paste into ESPHome)
# ESPHome YAML — ESP32 reading SHT31 and showing on SSD1306 OLED
esphome:
  name: sht31_node
  platform: ESP32
  board: esp32dev

wifi:
  ssid: "YOUR_SSID"
  password: "YOUR_PASSWORD"

logger:
api:
ota:

i2c:
  sda: 21
  scl: 22
  scan: true

sensor:
  - platform: sht3x
    temperature:
      name: "SHT31 Temperature"
      id: sht_temperature
    humidity:
      name: "SHT31 Humidity"
      id: sht_humidity
    update_interval: 30s

font:
  - file: "fonts/Roboto-Regular.ttf"
    id: font_reg
    size: 12
  - file: "fonts/Roboto-Regular.ttf"
    id: font_big
    size: 24

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(font_reg), "SHT31 Sensor");
      it.printf(0, 18, id(font_big), "%.1f°C", id(sht_temperature).state);
      it.printf(0, 44, id(font_reg), "RH: %.1f %%", id(sht_humidity).state);
    update_interval: 10s

Notes: change Wi-Fi creds and I²C pins as needed. Update OLED address if it's 0x3D. Upload fonts or use built-in fonts.

Arduino Example — ESP32 (Adafruit SHT31 + SSD1306)

Click to expand — Arduino sketch (ESP32 / Arduino core)
// Arduino (ESP32) — SHT31 + SSD1306 example
#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SHT31 sht31 = Adafruit_SHT31();
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22); // SDA = 21, SCL = 22 (ESP32)
  if (!sht31.begin(0x44)) {
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("SSD1306 allocation failed");
    while(1) delay(1);
  }
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
}

void loop() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();
  if (!isnan(t)) Serial.print("Temp: "), Serial.println(t);
  if (!isnan(h)) Serial.print("Hum: "), Serial.println(h);
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0,0);
  display.println("SHT31 Readings");
  display.setTextSize(2);
  display.setCursor(0,18);
  if (isnan(t) || isnan(h)) {
    display.println("Sensor error");
  } else {
    display.printf("%.1f C", t);
    display.setTextSize(1);
    display.setCursor(0,44);
    display.printf("RH: %.1f %%", h);
  }
  display.display();
  delay(5000);
}

Notes: Install Adafruit SHT31 and SSD1306 libraries. Confirm sensor address (0x44 or 0x45) and I²C wiring.

Compatibility & Tips

Shipping & Returns

Ships from UK. International shipping via Global Shipping Programme. 30-day returns accepted. policy.