Choosing a Temperature & Humidity Sensor

Compare DHT22, BME280, SHT31, SHT4x, and more — precision, features, and wiring differences to help you pick the right sensor for your ESP32 project

There are a lot of temperature and humidity sensors out there, and many of them look similar on paper. If you have ever stared at a parts list wondering whether you need a BME280, an SHT31, or something else entirely, this guide is for you. We will compare the most common options, explain what makes each one different, and help you pick the right sensor for your project.

Good news: most of these sensors use I2C and wire to your ESP32 the same way — just four connections (VCC, GND, SDA, SCL). Switching between them is mostly a matter of swapping the library and changing one or two lines of code.

🔗Quick Recommendations

Not sure where to start? Here are the short answers:

  • Just getting started? The DHT22 is cheap, widely available, and has the most beginner tutorials online.
  • Want temperature, humidity, AND pressure? The BME280 is the clear choice — three measurements from one sensor.
  • Need the best humidity accuracy? The SHT31 or SHT45 are the go-to options.
  • Need waterproof temperature sensing? The DS18B20 in its stainless steel probe form.
  • On a tight budget? A DHT11 works fine for basic room temperature readings.
  • Building something new and want the latest? The SHT4x series (SHT40, SHT41, SHT45) is Sensirion's newest generation.

🔗Comparison Table

This table covers the most commonly used sensors in ESP32 projects. Accuracy values are typical specs from the manufacturer datasheets.

SensorTemp AccuracyHumidity AccuracyPressureInterfaceI2C Address
DHT11$\pm 2\,\text{°C}$$\pm 5\,\%\,\text{RH}$NoSingle-wireN/A
DHT22$\pm 0.5\,\text{°C}$$\pm 2\text{--}5\,\%\,\text{RH}$NoSingle-wireN/A
DS18B20$\pm 0.5\,\text{°C}$N/ANoOneWireN/A
BME280$\pm 1\,\text{°C}$$\pm 3\,\%\,\text{RH}$YesI2C / SPI0x76 / 0x77
BMP280$\pm 1\,\text{°C}$NoneYesI2C / SPI0x76 / 0x77
SHT30$\pm 0.3\,\text{°C}$$\pm 3\,\%\,\text{RH}$NoI2C0x44 / 0x45
SHT31$\pm 0.3\,\text{°C}$$\pm 2\,\%\,\text{RH}$NoI2C0x44 / 0x45
SHT35$\pm 0.1\,\text{°C}$$\pm 1.5\,\%\,\text{RH}$NoI2C0x44 / 0x45
SHT40$\pm 0.2\,\text{°C}$$\pm 1.8\,\%\,\text{RH}$NoI2C0x44 / 0x45
SHT41$\pm 0.2\,\text{°C}$$\pm 1.8\,\%\,\text{RH}$NoI2C0x44 / 0x45
SHT45$\pm 0.1\,\text{°C}$$\pm 1.0\,\%\,\text{RH}$NoI2C0x44 / 0x45
HTU21D$\pm 0.3\,\text{°C}$$\pm 2\,\%\,\text{RH}$NoI2C0x40
Si7021$\pm 0.4\,\text{°C}$$\pm 3\,\%\,\text{RH}$NoI2C0x40

Note: All accuracy values are "typical" from the datasheets. Actual performance depends on conditions — accuracy tends to be best in the middle of the sensor's range (around $25\,\text{°C}$ and $25\text{--}75\,\%\,\text{RH}$) and degrades at the extremes.

🔗The Sensirion SHT3x Family

The SHT30, SHT31, and SHT35 are the same sensor at different precision tiers. Sensirion bins the chips during manufacturing: the ones that meet the tightest tolerances become SHT35s, the mid-tier ones become SHT31s, and the rest become SHT30s.

VariantTemp AccuracyHumidity AccuracyTypical Use
SHT30$\pm 0.3\,\text{°C}$$\pm 3\,\%\,\text{RH}$Budget projects where I2C is preferred over DHT
SHT31$\pm 0.3\,\text{°C}$$\pm 2\,\%\,\text{RH}$The sweet spot — most popular choice
SHT35$\pm 0.1\,\text{°C}$$\pm 1.5\,\%\,\text{RH}$High-precision applications

What they all share:

  • Same library — the Adafruit SHT31 library works for all three
  • Same wiring — I2C on address 0x44 (default) or 0x45
  • Same features — including a built-in heater to burn off condensation in humid environments
  • No minimum sampling interval — unlike the DHT22's $2\,\text{s}$ delay, you can read these as fast as your I2C bus allows

For most hobbyist projects, the SHT31 is the one to get. The SHT35's extra precision is only meaningful if you are building a calibration reference or scientific instrument.

See our SHT31 guide for wiring, code, and a detailed walkthrough.

🔗The Sensirion SHT4x Family

The SHT4x series is Sensirion's newer generation, designed to replace the SHT3x. It follows the same tiered precision model:

VariantTemp AccuracyHumidity AccuracyKey Improvement
SHT40$\pm 0.2\,\text{°C}$$\pm 1.8\,\%\,\text{RH}$Better than SHT30 in both temp and humidity
SHT41$\pm 0.2\,\text{°C}$$\pm 1.8\,\%\,\text{RH}$Tighter accuracy over the full humidity range
SHT45$\pm 0.1\,\text{°C}$$\pm 1.0\,\%\,\text{RH}$Best-in-class humidity accuracy

Compared to SHT3x, the SHT4x sensors offer:

  • Better accuracy across the board — the entry-level SHT40 already beats the SHT31 in temperature accuracy
  • Faster measurement — shorter response time
  • Lower power consumption — better for battery-powered projects
  • Same I2C wiring — address 0x44 (default) or 0x45, identical pin connections as SHT3x

The catch: SHT4x uses a different library (Adafruit SHT4x) with a slightly different API. The wiring is the same, but the code needs minor changes. Also, because SHT3x and SHT4x share the same I2C addresses, you cannot use one of each on the same I2C bus without an address conflict.

If you are starting a new project today and the SHT4x is available at a reasonable price, it is the better choice. But the SHT3x is not obsolete — it is still widely available, well-documented, and perfectly good.

🔗The Bosch BME/BMP Family

Bosch's environmental sensors are popular because they pack multiple measurements into a single chip.

🔗BME280 — The All-Rounder

The BME280 measures temperature, humidity, and barometric pressure. It is the most popular choice for weather station projects because you get three readings from one sensor and one I2C connection.

  • I2C address: 0x76 (default) or 0x77
  • Also available with SPI interface
  • Library: Adafruit BME280

🔗BMP280 — No Humidity

The BMP280 is the BME280's cheaper sibling. It measures temperature and pressure only — no humidity. This is the single most common source of confusion for beginners.

These two sensors look nearly identical. The breakout boards are often the same size, colour, and layout. Many sellers (especially on AliExpress and eBay) mislabel the BMP280 as a BME280. If you buy a "BME280" and your humidity readings are always $0\,\%$, you almost certainly have a BMP280.

How to tell them apart:

  • Check the tiny text printed on the chip itself — it says either "BME280" or "BMP280"
  • In your code, read humidity — if it always returns exactly $0\,\%$ or NaN, it is a BMP280
  • When in doubt, buy from a reputable supplier (Adafruit, SparkFun) where the listing matches the product

The BMP280 is fine if you only need temperature and pressure (for example, altitude estimation). It is cheaper and uses the same wiring and I2C addresses as the BME280.

🔗BME680 / BME688 — Air Quality

For completeness: Bosch also makes the BME680 and BME688, which add a gas resistance sensor for air quality (VOC) measurement on top of temperature, humidity, and pressure. These are more expensive and more complex to use, but worth knowing about if air quality matters for your project. See our SGP30 guide for a dedicated air quality sensor alternative.

🔗SPI Interface

The BME280 and BMP280 both support SPI in addition to I2C. SPI uses four data lines (MOSI, MISO, SCK, CS) instead of two, but offers faster communication. For most ESP32 hobby projects, I2C is simpler and fast enough — SPI is mainly useful if you are already using SPI for another device (like an SD card) and want to share the bus, or if you need to run multiple BME280s at the same time (I2C only supports two addresses, but SPI can use any GPIO as a chip-select pin).

To use SPI with the Adafruit BME280 library, pass the CS pin to bme.begin():

#define BME_CS 5  // GPIO 5 as chip select
Adafruit_BME280 bme(BME_CS);  // SPI mode

🔗Budget Sensors and Common Confusions

Not every project needs a high-precision sensor. Here is what the cheaper options give you — and what they sacrifice.

🔗DHT11 vs. DHT22

Both are single-wire sensors that come on the same style of breakout board. The code is identical — only the DHTTYPE constant changes.

DHT11DHT22
Temp accuracy$\pm 2\,\text{°C}$$\pm 0.5\,\text{°C}$
Humidity accuracy$\pm 5\,\%\,\text{RH}$$\pm 2\text{--}5\,\%\,\text{RH}$
Humidity range$20\text{--}80\,\%$$0\text{--}100\,\%$
PriceCheapest sensor availableAbout twice the price of DHT11

The DHT11 is fine for "is this room roughly warm or cold?" readings. For anything where accuracy matters — logging, automation thresholds, display — get the DHT22 or step up to I2C sensors.

See our DHT22 guide for wiring and code that works with both DHT11 and DHT22.

🔗HTU21D and Si7021

These are budget I2C humidity sensors that fill the gap between the DHT series and the premium Sensirion chips. They offer decent accuracy at a low price and use I2C (address 0x40), which means simpler wiring than the DHT sensors — no pull-up resistor needed, and you can share the bus with other I2C devices.

HTU21DSi7021
Temp accuracy$\pm 0.3\,\text{°C}$$\pm 0.4\,\text{°C}$
Humidity accuracy$\pm 2\,\%\,\text{RH}$$\pm 3\,\%\,\text{RH}$
LibrarySparkFun HTU21D or Adafruit HTU21DFAdafruit Si7021

These are perfectly good sensors. The Si7021 in particular was very popular before the SHT3x series took over. If you find one cheap or already have one, there is no reason not to use it.

🔗What You Actually Lose with Cheaper Sensors

For many beginner projects — displaying room temperature on an OLED, sending readings to Home Assistant, triggering a fan at a threshold — even a DHT11 works fine. You lose precision, but most people cannot perceive a $2\,\text{°C}$ temperature difference or a $5\,\%$ humidity difference without instruments.

Accuracy matters more when you are:

  • Comparing readings between multiple sensors (they need to agree)
  • Controlling something with tight thresholds (HVAC, greenhouse, fermentation)
  • Logging data over time (drift and noise become visible)
  • Measuring in extreme conditions (very hot, very cold, very humid)

🔗I2C Address Quick Reference

If you are planning a project with multiple sensors on the same I2C bus, check this table for address conflicts.

SensorDefaultAlternateConflict Notes
BME280 / BMP2800x760x77No conflict with SHT or HTU sensors
SHT30 / SHT31 / SHT350x440x45Conflicts with SHT4x (same addresses)
SHT40 / SHT41 / SHT450x440x45Conflicts with SHT3x (same addresses)
HTU21D / Si70210x40No alternate address; no conflict with above
DS18B20N/AN/AUses OneWire, not I2C — no conflict
DHT11 / DHT22N/AN/AUses single-wire protocol — no conflict

Tip: You can safely use an SHT31 and a BME280 on the same I2C bus — they use different addresses. But you cannot use an SHT31 and an SHT40 together without hardware modification, because they both default to 0x44.

🔗Which Sensor Should You Pick?

Still not sure? Here is a scenario-based guide:

Your SituationRecommended SensorWhy
First project, just learningDHT22Cheapest, simplest, most tutorials available
Want the best value for accuracySHT31Great precision at a reasonable price
Weather station (temp + humidity + pressure)BME280Three measurements from one sensor
Best possible humidity readingsSHT45Top-tier accuracy from Sensirion's latest generation
Battery-powered sensor nodeSHT40Low power consumption, fast measurements, good accuracy
Waterproof / outdoor temperatureDS18B20Available in sealed stainless steel probe form
Tightest possible budgetDHT11Works, but you get what you pay for
Already have a BMP280 and want humidityAdd an SHT31Different I2C addresses, so they share the bus without conflict

🔗Next Steps