How to choose a sensor
Start from what you need to know, not from the sensor in your kit. A room thermometer is fine at ±0.5 °C; mould prevention or a greenhouse is worth a ±2 %RH humidity sensor; a weather station that compares pressure with forecasts needs good absolute accuracy, while an altimeter needs good relative accuracy.
Then check how it connects. I²C sensors share two wires with other devices as long as their addresses differ; the DHT11 and DHT22 use their own single-wire protocol, the DS18B20 uses 1-Wire, and most CO₂ and particle sensors use a UART. On ESP32 and Raspberry Pi Pico boards, prefer sensors that run from 3.3 V or whose data lines work at 3.3 V.
Temperature and humidity: placement matters more than the chip
Relative humidity depends on temperature: a sensor 2 °C warmer than the room reads several %RH too low, whatever its datasheet says. Put it away from the microcontroller, the regulator and the Wi-Fi antenna, ideally on a short cable or in a vented enclosure, and keep it out of direct sun.
The DHT11 and DHT22 are cheap and easy, but slow and less accurate. The AHT20, SHT31, SHT4x, HTU21D, Si7021 and HDC1080 are I²C sensors with ±0.2 to ±0.3 °C typical; of these, the SHT4x is the most accurate on humidity. The BME280 adds pressure at the cost of some accuracy, and the DS18B20 and TMP117 measure temperature only.
Real CO₂ or eCO₂
NDIR and photoacoustic sensors (MH-Z19C, SCD30, SCD40, SCD41) measure CO₂ itself, which tells you when a room needs air. Metal-oxide sensors (SGP30, SGP40, SGP41, ENS160, CCS811, BME680) react to volatile organic compounds: some estimate an “eCO₂” from them, but that isn’t a CO₂ measurement. They are good at spotting cooking, cleaning products or paint, and they are smaller and cheaper.
Ultrasonic, infrared or laser for distance
Ultrasonic modules such as the HC-SR04 have a wide beam and work on glass and dark surfaces, but soft materials absorb the echo. Laser time-of-flight sensors (VL53L0X, VL53L1X, VL53L4CD) and the TF-Luna LiDAR have a narrow beam and read small targets, but sunlight and dark surfaces cut their range. For water tanks, the waterproof JSN-SR04T is the usual choice.
Each I²C sensor links to its page in the I²C address list, with wiring, pull-ups and conflicts. For battery projects, add the sensor’s current to the rest of the board in the battery life calculator.
Sources: the makers’ datasheets and product pages (Sensirion, Bosch Sensortec, Texas Instruments, Analog Devices, Silicon Labs, TE Connectivity, Aosong, Infineon, STMicroelectronics, Benewake, Sharp, ROHM, ams OSRAM, Vishay, Winsen, ScioSense, Plantower, Nova Fitness) and the ESPHome documentation, checked in November 2026.
Frequently asked questions
Which temperature and humidity sensor is best for an ESP32?
For accuracy, a Sensirion SHT4x or SHT31 on I²C: ±0.2 °C and ±1.8 or ±2 %RH typical. The AHT20 costs less and comes close (±0.3 °C, ±2 %RH). Choose the BME280 if you also want pressure, and keep the DHT22 for simple projects. Whatever you pick, mount it away from the board’s warm parts.
DHT22 or BME280: which should I use?
The DHT22 is specified at ±0.5 °C and ±2 %RH typical, the BME280 at ±1 °C (±0.5 °C at 25 °C) and ±3 %RH. The BME280 adds pressure, works on I²C or SPI and draws 0.1 µA in sleep against about 50 µA, so it suits battery projects; the DHT22 is slow and uses its own single-wire protocol. For accurate humidity, an SHT4x beats both.
Why does my sensor read low humidity indoors?
Usually because it is warmer than the room. Relative humidity falls as temperature rises, so a sensor heated by the microcontroller, the regulator or the sun reads too dry. Move it away from the board, on a short cable or in a vented enclosure, and compare it with another sensor after a few minutes.
Do the SGP30, ENS160 or CCS811 measure CO₂?
No. They are metal-oxide gas sensors that react to volatile organic compounds and estimate an “eCO₂” from them. To know the real CO₂ level, for example to decide when to air a room, use an NDIR or photoacoustic sensor such as the SCD40, SCD41, SCD30 or MH-Z19C.
HC-SR04 or VL53L0X?
The HC-SR04 reaches 4 m with a wide beam and sees glass, but it needs 5 V and a divider on its echo pin for 3.3 V boards. The VL53L0X is a small laser sensor on I²C at 3.3 V with a narrow beam: about 1.2 m on white indoors, up to 2 m in the dark, and less in sunlight. For water tanks, use the waterproof JSN-SR04T.
Can I connect two sensors with the same I²C address?
Only if the sensor lets you change it: many have an address pin (BME280, SHT31, TMP117), the VL53 sensors can be renumbered in software, and on the SHT4x the address depends on the part code. Otherwise use a multiplexer such as the TCA9548A, or a second I²C bus on the ESP32.
Which of these sensors work with ESPHome?
Most have an official ESPHome component, named in the table. The VL53L1X, the VL53L4CD and the Sharp GP2Y0A21 don’t; the Sharp sensor can still be read with the adc component. This site’s ESPHome generator writes the configuration for the DHT11, DHT22, BME280, SHT3x and DS18B20.