DHT22 vs BME280 vs SHT31: Picking the Right Temperature and Humidity Sensor
Every weather station, greenhouse monitor, and room logger starts with the same decision. All three of these sensors will give you a temperature and a humidity number. What separates them is how accurate that number is, how much work it takes to read it, and how they behave after six months in a real environment.
The short answer
- DHT22 — cheapest, easiest to find, worst accuracy and slowest. Fine for "is the greenhouse roughly 25 °C or roughly 35 °C".
- BME280 — the default choice for most projects. Good accuracy, I2C or SPI, and it throws in a barometric pressure reading for free.
- SHT31 — the accuracy pick. Best humidity performance of the three, with an onboard heater for condensing environments. Costs more.
If you are building a weather station and cannot decide, buy the BME280. The pressure channel alone makes it worth it, and the accuracy is good enough for nearly everything.
Specifications side by side
| Specification | DHT22 (AM2302) | BME280 | SHT31-D |
|---|---|---|---|
| Temperature accuracy | ±0.5 °C | ±1.0 °C (±0.5 °C typical, 25 °C) | ±0.2 °C |
| Humidity accuracy | ±2–5 % RH | ±3 % RH | ±2 % RH |
| Pressure | No | Yes, ±1 hPa | No |
| Interface | Single-wire proprietary | I2C or SPI | I2C |
| Max sample rate | 0.5 Hz (one reading / 2 s) | Up to 157 Hz | Up to 10 Hz |
| Supply voltage | 3.3–6 V | 1.7–3.6 V | 2.4–5.5 V |
| Typical current | ~1.5 mA active | ~3.6 µA @ 1 Hz | ~1.5 mA active, 0.2 µA idle |
| Onboard heater | No | No | Yes |
| I2C addresses | N/A | 0x76 / 0x77 | 0x44 / 0x45 |
DHT22: cheap, and you get what you pay for
The DHT22 is the sensor most tutorials use, largely for historical reasons. It works, and for coarse measurements it is fine.
The problems are real though:
The protocol is proprietary and timing-sensitive. It is not I2C, not SPI, not UART — it is a custom single-wire scheme with microsecond-level timing requirements. On an ESP32 running FreeRTOS and a WiFi stack, an interrupt at the wrong moment corrupts the read. You will see intermittent nan readings. Libraries handle retries, but the underlying fragility does not go away.
It is slow. One reading every two seconds, maximum. That rules out anything responsive.
Humidity drift is significant. DHT22 units commonly drift several percent RH over a year, and there is no calibration path. Two DHT22s side by side frequently disagree by 3–4 % RH out of the box.
Buy a DHT22 when: budget is the dominant constraint, you need one reading every few minutes, and ±5 % humidity is acceptable.
BME280: the sensible default
Bosch's BME280 is the sensor we recommend most often, and it is what our ESP32 weather station build uses.
Standard I2C. Two wires, a well-supported library, no timing games. Runs happily alongside an OLED on the same bus — see the I2C communication guide if you are new to sharing a bus.
Pressure for free. ±1 hPa barometric pressure enables altitude estimation and short-term weather trend prediction. Neither of the other two sensors offers this.
Genuinely low power. In forced mode, sampling once per second, it draws around 3.6 µA. Paired with ESP32 deep sleep, a battery-powered node can run for months.
Configurable oversampling and filtering. You control the noise/power/speed tradeoff in software rather than accepting a fixed behaviour.
The self-heating gotcha
The most common BME280 complaint is that temperature reads 1–2 °C high. This is almost always self-heating, not a faulty sensor.
Causes and fixes:
- Continuous ("normal") mode at high sample rates warms the die. Use forced mode: take one reading, return to sleep. This alone usually fixes it.
- Mounting on a board next to a warm regulator or an ESP32 conducts heat in. Physically separate the sensor, or use a breakout on a short cable.
- No airflow in a sealed enclosure. Ventilate the housing.
The address gotcha
BME280 breakouts ship with the address strapped to either 0x76 or 0x77 depending on the vendor. If begin() fails, try the other one before assuming the board is dead. Run an I2C scanner first.
BMP280 is not BME280
Watch the part number when ordering. The BMP280 has no humidity sensor — only temperature and pressure. They look nearly identical and are often mislabelled by cheap sellers. The BME280 is a 8-pin package; genuine Bosch parts are laser-marked. If humidity is why you bought it, verify the marking.
Buy a BME280 when: you want a good general-purpose environmental sensor, especially for weather, altitude, or battery-powered logging.
SHT31: when the humidity number has to be right
Sensirion's SHT31-D is the accuracy option. ±2 % RH and ±0.2 °C, with much better long-term stability than either alternative.
The onboard heater is the killer feature. In high-humidity or condensing environments — greenhouses, bathrooms, outdoor enclosures, cold rooms — moisture condenses on the sensing element and readings saturate at 100 % RH until it dries. The SHT31 can pulse an integrated heater to drive that moisture off, then resume measuring. Neither the DHT22 nor the BME280 can recover from condensation on their own.
Wide supply range. 2.4–5.5 V, so it works directly on both 3.3 V and 5 V systems without level shifting — one of the few sensors where that is true.
Fast and repeatable. Up to 10 Hz, with selectable repeatability modes trading speed against noise.
The cost is price and the lack of a pressure channel.
Buy an SHT31 when: humidity accuracy actually matters — curing, storage, HVAC, agriculture — or when condensation is likely.
Which to pick, by project
| Project | Recommended sensor | Why |
|---|---|---|
| Indoor room logger | BME280 | Accuracy is plenty, pressure is a bonus |
| Outdoor weather station | BME280 | Pressure enables trend prediction |
| Greenhouse / mushroom tent | SHT31 | Condensation recovery via heater |
| Battery sensor node, months of runtime | BME280 | Lowest sleep current, forced mode |
| Altitude / vertical position | BME280 | Only one with a barometer |
| Cold storage monitoring | SHT31 | Accuracy plus heater at low temperature |
| Learning project, tight budget | DHT22 | Cheapest path to a working reading |
| Fast-responding control loop | SHT31 | 10 Hz vs 0.5 Hz on DHT22 |
Wiring notes that save an afternoon
All three on an ESP32 are 3.3 V devices in practice. The DHT22 and SHT31 tolerate 5 V supply, but if you power them from 5 V their data lines will output 5 V logic, which the ESP32 does not tolerate. Power them from 3.3 V.
I2C pull-ups. Most BME280 and SHT31 breakouts include 4.7 kΩ pull-ups on SDA and SCL. Stack three or four such breakouts on one bus and the parallel pull-ups get too strong, and the bus stops working. Remove the pull-ups on all but one board.
Cable length. I2C is designed for on-board distances. Beyond about 50 cm you will see errors. For a sensor 10 m away, either drop the bus speed substantially, use an I2C extender, or put a second microcontroller at the sensor and send readings over MQTT or LoRa.
Calibration reality check
None of these are laboratory instruments. If your readings need to be traceable, you need a reference and an offset table.
A practical field check: seal the sensor in a small airtight container with a saturated salt solution. Sodium chloride gives 75 % RH at 25 °C; magnesium chloride gives 33 %. Let it stabilise for several hours, then record the offset. This costs nothing and tells you far more than a datasheet tolerance figure.
Summary
The DHT22 is a teaching sensor. The BME280 is the right answer for most real projects. The SHT31 is what you buy when the humidity reading is the point of the project rather than a nice-to-have.
All three, along with the ESP32 boards and OLED displays to pair them with, are stocked at Wavtron with datasheets, GST invoicing, and same-day dispatch across India.
