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.

SHT40 with ESP32 DevKit V1 — 3.3 V wiring and heater pulse code

Connect an SHT40/SHT41/SHT45 to an ESP32 DevKit V1 at 3.3 V on GPIO21/22, read high-precision temperature and humidity, and use a 1 s heater pulse when wet.

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

Community draft — report a mistake

The SHT40 is Sensirion’s newest low-cost humidity sensor: smaller and more accurate than the SHT31, with a pulsed heater for wet conditions.

On the ESP32 DevKit V1 it is a four-wire job on 3V3 and D21/D22. The sketch reads in high-precision mode every two seconds and fires a one-second heater pulse when humidity goes above 95 % — useful in monsoon and cold-storage logging.

Wiring

ESP32 DevKit V1Only the pins used are shown · 3.3 V logicSHT40 temperature and humidity sensorGNDD22D213V3VCCGNDSCLSDA
Every connection
ESP32 DevKit V1SHT40 temperature and humidity sensorWireNotes
3V3VCCredThe chip is 3.6 V max. Plain 4-pin clones have no regulator — never VIN.
GNDGNDblack
D22SCLyellow
D21SDAblue

3.3 V (boards with a regulator: 3.3–5 V) part, 3.3 V board. The chip is 1.08–3.6 V only. Boards with a regulator and level shifting (Adafruit-style, with a VIN pin) accept 5 V. Plain 4-pin clones often have neither — power them from 3.3 V and keep SDA/SCL at 3.3 V; on an Uno use a level shifter.

Board quirks

  • Bare 4-pin SHT40 clones have no regulator or level shifter, so 3V3 is the only safe supply. The ESP32 is a 3.3 V board, so it needs nothing in between.
  • The heater in the SHT4x runs in timed pulses (here 1 s at medium power). Readings for several seconds afterwards are warm, so the sketch waits 8 s before the next one.
  • High-precision mode takes about 9 ms per reading. For battery nodes in deep sleep, SHT4X_LOW_PRECISION (≈2 ms) saves more than it costs.
  • SHT40, SHT41 and SHT45 differ only in accuracy and all answer at 0x44 with this library; the serial number printed at start-up tells two sensors apart.

Code

sht40-esp32.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// SHT40 / SHT41 / SHT45 temperature + humidity on an ESP32 DevKit V1 (address 0x44).
// VCC → 3V3, GND → GND, SCL → D22, SDA → D21.
#include <Wire.h>
#include <Adafruit_SHT4x.h>

Adafruit_SHT4x sht4;

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!sht4.begin(&Wire)) {
    Serial.println("No SHT4x at 0x44 — check wiring and 3V3");
    while (true) delay(1000);
  }
  Serial.printf("SHT4x serial 0x%08lX\n", (unsigned long)sht4.readSerial());
  sht4.setPrecision(SHT4X_HIGH_PRECISION);  // ~9 ms per reading
  sht4.setHeater(SHT4X_NO_HEATER);
}

void loop() {
  sensors_event_t humidity, temp;
  sht4.getEvent(&humidity, &temp);
  Serial.printf("Temp %.2f °C  Humidity %.1f %%\n", temp.temperature, humidity.relative_humidity);

  // In condensing air (monsoon nights) a short heater pulse dries the sensor.
  // Skip the reading right after it — the chip is hot for a few seconds.
  if (humidity.relative_humidity > 95) {
    sht4.setHeater(SHT4X_MED_HEATER_1S);
    sht4.getEvent(&humidity, &temp);  // this reading runs the 1 s heater pulse
    sht4.setHeater(SHT4X_NO_HEATER);
    Serial.println("Heater pulse (1 s) — next reading may be warm");
    delay(8000);
  }
  delay(2000);
}

Library: Adafruit SHT4x Library (Adafruit (also install Adafruit Unified Sensor and Adafruit BusIO)) — compiled with Adafruit SHT4x Library 1.0.5.

Expected serial output

Serial Monitor · 115200Output
SHT4x serial 0x0F3A2B1C
Temp 26.91 °C  Humidity 68.2 %
Temp 26.92 °C  Humidity 68.1 %

Common errors

“No SHT4x at 0x44”

Wiring, or a 0x45/0x46 variant (SHT40-BD1B etc.). Run the I2C scanner to see the real address.

Temperature jumps up by 5–10 °C now and then

A heater pulse just ran. That is expected when humidity was above 95 %; ignore readings for a few seconds after it.

Sensor dead after connecting to VIN

5 V on a regulator-less 4-pin board destroys the chip. Use 3V3.

↑↓ to move · Enter to open