The SHT31 is a high-accuracy digital temperature and humidity sensor made by Sensirion. If you need more precise humidity readings than what the DHT22 can provide, the SHT31 is an excellent upgrade. It communicates over I2C, responds quickly, and includes a built-in heater element that can burn off condensation -- a thoughtful feature for sensors deployed in damp environments.
This guide uses the ESP32-WROOM-32 DevKit. Pin labels may differ on your board -- check your board's pinout diagram.
🔗Key Specs
| Parameter | Value |
|---|---|
| Temperature range | $-40$ to $+125\,\text{°C}$ |
| Temperature accuracy | $\pm 0.3\,\text{°C}$ |
| Humidity range | $0$ to $100\,\%\,\text{RH}$ |
| Humidity accuracy | $\pm 2\,\%\,\text{RH}$ |
| Supply voltage | $2.4$ to $5.5\,\text{V}$ |
| Interface | I2C |
| I2C address | 0x44 (default) or 0x45 |
| Built-in heater | Yes (for clearing condensation) |
Compared to the DHT22 ($\pm 0.5\,\text{°C}$ temperature accuracy), the SHT31 offers noticeably better temperature precision at $\pm 0.3\,\text{°C}$. It also has no minimum sampling interval like the DHT22's $2\,\text{s}$ delay -- you can read it as fast as your I2C bus allows.
Alternatives: Need barometric pressure too? The BME280 adds pressure to its temperature and humidity readings — ideal for weather stations. The newer SHT4x series (SHT40, SHT41, SHT45) is Sensirion's next generation with better accuracy and lower power, using the same wiring. See our sensor comparison guide for help choosing.
🔗What You'll Need
| Component | Qty | Notes | Buy |
|---|---|---|---|
| ESP32 dev board | 1 | AliExpress | Amazon.de .co.uk .com | |
| SHT31 sensor module | 1 | AliExpress | Amazon.de .co.uk .com | |
| Breadboard | 1 | AliExpress | Amazon.de .co.uk .com | |
| Jumper wires | 4 | AliExpress | Amazon.de .co.uk .com |
Links marked Amazon/AliExpress are affiliate links. We may earn a small commission at no extra cost to you.
🔗Wiring (I2C)
| SHT31 Pin | ESP32 Pin | Notes |
|---|---|---|
| VIN / VCC | 3.3V | Some modules accept up to 5V |
| GND | GND | |
| SDA | GPIO 21 | Default I2C data line on ESP32 |
| SCL | GPIO 22 | Default I2C clock line on ESP32 |
Pin labels, GPIO numbers, and ADC channels vary between ESP32 boards. GPIOs 21 (SDA) and 22 (SCL) are the default I2C pins on most ESP32-WROOM-32 DevKit boards, but your board may differ. Always check your board's pinout diagram.
🔗I2C Address
The default I2C address is 0x44. If you need to use two SHT31 sensors on the same bus, you can change one to 0x45 by pulling the ADDR pin high. Check your breakout board for an ADDR solder jumper or pad.
🔗Required Libraries
Install the following through the Arduino Library Manager:
- Adafruit SHT31 Library by Adafruit -- provides the main sensor interface
- Adafruit BusIO by Adafruit -- a dependency for I2C communication
To install:
- Go to Sketch > Include Library > Manage Libraries...
- Search for Adafruit SHT31 and install it
- Accept any prompts to install dependencies
🔗Code Example
This sketch reads temperature and humidity from the SHT31 and prints both values to the Serial Monitor.
#include <Wire.h>
#include <Adafruit_SHT31.h>
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(115200);
Serial.println("SHT31 Sensor Test");
if (!sht31.begin(0x44)) {
Serial.println("Error: Could not find SHT31 sensor.");
Serial.println("Check wiring or try address 0x45.");
while (1) delay(10); // Halt
}
Serial.println("SHT31 sensor found.");
// Check if the heater is enabled (it should be off by default)
Serial.print("Heater enabled: ");
Serial.println(sht31.isHeaterEnabled() ? "YES" : "NO");
}
void loop() {
float temperature = sht31.readTemperature();
float humidity = sht31.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Error: Failed to read from SHT31 sensor.");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature, 2);
Serial.print(" °C | Humidity: ");
Serial.print(humidity, 2);
Serial.println(" %");
delay(2000);
}🔗Using the Built-In Heater
The SHT31 has a small built-in heater that can raise the sensor temperature by a few degrees. This might sound odd for a temperature sensor, but it serves an important purpose: in very humid environments, condensation can form on the sensor element and cause the humidity reading to saturate at 100%. Briefly activating the heater evaporates the condensation and restores accurate readings.
// Turn the heater on
sht31.heater(true);
Serial.println("Heater ON");
delay(10000); // Run for 10 seconds
// Turn the heater off
sht31.heater(false);
Serial.println("Heater OFF");
delay(5000); // Wait for the sensor to return to ambient temperatureWarning: Do not leave the heater running continuously. It increases power consumption and will cause the temperature reading to be artificially high. Use it briefly and only when needed -- for example, once every few hours in a humid environment. Always wait several seconds after turning off the heater before taking a temperature reading.
🔗How It Works
The SHT31 uses a capacitive humidity sensor and a band-gap temperature sensor on a single CMOS chip. When you request a measurement over I2C, the sensor performs an internal analog-to-digital conversion, applies factory calibration, and returns the results along with a CRC checksum for data integrity. The Adafruit library verifies this checksum automatically.
Because the SHT31 is a true digital sensor with factory calibration, it requires no manual calibration and provides consistent readings out of the box.
🔗Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| "Could not find SHT31" | Wrong I2C address | Try 0x45 instead of 0x44 |
| "Could not find SHT31" | Wiring issue | Verify SDA/SCL connections and power |
Readings return NaN | Communication error | Check wiring; try a slower I2C clock speed |
| Humidity stuck near 100% | Condensation on sensor element | Activate the built-in heater briefly to clear moisture |
| Temperature reads slightly high | Self-heating or heater left on | Ensure heater is off; mount sensor away from heat sources |
| Two sensors not working | Address conflict | Set one sensor to 0x45 using the ADDR pin |
🔗Next Steps
- Deploy the SHT31 in a greenhouse or terrarium for precision humidity monitoring
- Compare SHT31 readings against a DHT22 or BME280 to see the accuracy difference firsthand
- Build a humidity alert system that triggers a relay or buzzer when levels get too high
- Pair the SHT31 with a BH1750 light sensor for a comprehensive indoor environment monitor