Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

SHT31 with ESP32 DevKit V1 — accurate humidity, heater for monsoon

Connect an SHT31 to an ESP32 DevKit V1 at 3.3 V on GPIO21/22, pick 0x44 or 0x45 with ADR, and use the built-in heater to clear condensation in humid weather.

Arduino C++Verified — core esp32 3.3.12, Adafruit SHT31 Library 2.2.2, 3 Nov 2026Compile-only

Community draft — report a mistake

The SHT31 is the humidity sensor to pick when a DHT22 isn’t accurate enough: a factory-calibrated Sensirion chip on I2C, with an on-chip heater.

On the ESP32 DevKit V1 it runs at 3.3 V on D21/D22 with no extra parts, and the ADR pin lets two sensors share the bus (indoor and outdoor, for example). The sketch prints readings every two seconds and runs a short heater cycle when the sensor has been saturated for ten minutes.

Wiring

ESP32 DevKit V1Only the pins used are shown · 3.3 V logicSHT31-DGNDD22D213V3VINGNDSCLSDAADRAL (not connected)
Every connection
ESP32 DevKit V1SHT31-DWireNotes
3V3VINredThe breakout’s pull-ups follow VIN, so 3V3 keeps SDA/SCL at 3.3 V.
GNDGNDblack
D22SCLyellow
D21SDAblue
GNDADRblackADR to GND = 0x44. Tie it to 3V3 for 0x45 when using two sensors.

2.4–5.5 V part, 3.3 V board. Power VCC from your board's logic voltage; the breakout's pull-ups follow VCC, so they match 3.3 V or 5 V boards.

Board quirks

  • The SHT31 is ±2 % RH and ±0.3 °C — a real step up from a DHT11/DHT22, and it shares the I2C bus instead of needing its own pin.
  • The sketch turns the on-chip heater on for 5 s after 10 minutes above 95 % RH. In Indian monsoon nights the sensor can sit in condensing air and read 100 % for hours; a short heat cycle clears it.
  • AL is an alert output the Adafruit library doesn’t use — leave it unconnected.
  • A CRC error (NaN) on long cables means the bus is too slow to settle. Keep I2C under about 1 m, or add stronger 2.2 kΩ pull-ups to 3V3.

Code

sht31-esp32.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// SHT31 temperature + humidity on an ESP32 DevKit V1.
// VIN → 3V3, GND → GND, SCL → D22, SDA → D21. ADR → GND = 0x44 (ADR → 3V3 = 0x45).
#include <Wire.h>
#include <Adafruit_SHT31.h>

Adafruit_SHT31 sht31(&Wire);

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!sht31.begin(0x44) && !sht31.begin(0x45)) {
    Serial.println("No SHT31 at 0x44 or 0x45 — check wiring");
    while (true) delay(1000);
  }
  Serial.println("SHT31 ready");
}

void loop() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();
  if (isnan(t) || isnan(h)) {
    Serial.println("SHT31 read failed (CRC error) — check cable length");
  } else {
    Serial.printf("Temp %.2f °C  Humidity %.1f %%\n", t, h);
  }

  // After long spells above 95 % RH (monsoon, cold rooms) run the built-in heater for a
  // few seconds to drive off condensation. Readings taken while it is on read hot.
  static uint32_t wetSince = 0;
  if (h > 95) {
    if (!wetSince) wetSince = millis();
    if (millis() - wetSince > 10UL * 60 * 1000) {
      Serial.println("Heater on for 5 s to dry the sensor");
      sht31.heater(true);
      delay(5000);
      sht31.heater(false);
      wetSince = 0;
    }
  } else {
    wetSince = 0;
  }
  delay(2000);
}

Library: Adafruit SHT31 Library (Adafruit) — compiled with Adafruit SHT31 Library 2.2.2.

Expected serial output

Serial Monitor · 115200Output
SHT31 ready
Temp 27.86 °C  Humidity 71.4 %
Temp 27.87 °C  Humidity 71.3 %

Common errors

“No SHT31 at 0x44 or 0x45”

Wiring or power. Check SDA on D21, SCL on D22, VIN on 3V3. The I2C scanner confirms the address.

Humidity stuck at 100 % after rain

Condensation on the sensor. Let the heater logic run or mount the sensor under a vented cover so water can’t settle on it.

Temperature 2–3 °C high

Board heat. Keep the sensor away from the ESP32 module and its regulator, and don’t run the heater constantly.

↑↓ to move · Enter to open