Comparison Guide to Temperature and Humidity Sensors for Arduino

Choosing the right environmental sensor can make the difference between a frustrating prototype and a reliable weather station or smart home controller. Beginners often grab the first inexpensive module they see, only to discover later that it responds too slowly, drifts over time, or lacks the accuracy required for their application. This comparison guide to temperature and humidity sensors examines five popular modules used with Arduino boards: the DHT11, DHT22 (AM2302), AHT10, BME280, and SHT31.

Illustration

By the end of this guide, you will understand the trade-offs in measurement accuracy, operating range, communication protocols, and voltage compatibility across these five sensors. You will also get a quick comparison table, an Arduino Uno test setup using the BME280 over I2C, and practical advice on how to pick the best sensor for indoor logging, outdoor weather stations, or battery-powered nodes.

How Temperature and Humidity Sensors Work

Digital temperature and humidity sensors combine two sensing elements and an onboard analog-to-digital converter inside a single compact package. Instead of outputting a raw analog voltage that fluctuates over long wires, these chips process the readings internally and transmit calibrated digital numbers to your microcontroller.

  1. A capacitive humidity sensing element absorbs or releases water vapor from the surrounding air, which changes the electrical capacitance between two microscopic electrodes.
  2. A thermistor or bandgap temperature sensor measures the ambient temperature by tracking predictable changes in electrical resistance or semiconductor voltage.
  3. An integrated microcontroller inside the sensor reads both raw signals, applies factory-stored calibration coefficients, and compensates for temperature effects on the humidity reading.
  4. The sensor sends the final temperature and relative humidity values to the Arduino over either a single-wire proprietary protocol or a standard I2C bus.

Relative Humidity (%) = (Actual Water Vapor Density / Saturation Water Vapor Density) x 100

Because warm air holds more moisture than cold air, relative humidity changes whenever the temperature shifts, which is why every digital humidity sensor must measure temperature simultaneously.

Hardware and Settings

To compare these sensors side by side and run a benchmark test sketch on an Arduino Uno, review the core sensor specifications and test hardware below.

ItemChoiceReason
MicrocontrollerArduino UnoStandard 5 V development board with I2C and digital GPIO pins
Entry-Level SensorDHT11 ModuleLow-cost 1-wire sensor for basic indoor classroom demos
Mid-Range 1-Wire SensorDHT22 (AM2302)Wider temperature range and better accuracy than DHT11
Budget I2C SensorAHT10 BreakoutFast I2C communication and solid accuracy at a low price
Multi-Sensor I2C BreakoutBME280 (3.3 V / 5 V module)Measures temperature, humidity, and barometric pressure
High-Precision I2C SensorSHT31-D BreakoutIndustrial-grade accuracy, repeatability, and built-in heater
Prototyping GearBreadboard and jumper wiresSolderless connections for quick sensor swapping

Sensor Specifications Comparison

Each sensor family targets a different balance of cost, speed, and precision. Use the table below to match a sensor to your project requirements.

SpecificationDHT11DHT22 (AM2302)AHT10BME280SHT31
Interface1-Wire Proprietary1-Wire ProprietaryI2C (0x38)I2C (0x76 or 0x77) / SPII2C (0x44 or 0x45)
Operating Voltage3.3 V to 5.5 V3.3 V to 6 V1.8 V to 3.6 V1.71 V to 3.6 V (chip)2.4 V to 5.5 V
Temperature Range0 C to 50 C-40 C to 80 C-40 C to 85 C-40 C to 85 C-40 C to 125 C
Temperature Accuracy+/- 2.0 C+/- 0.5 C+/- 0.3 C+/- 1.0 C+/- 0.2 C
Humidity Range20% to 90% RH0% to 100% RH0% to 100% RH0% to 100% RH0% to 100% RH
Humidity Accuracy+/- 5% RH+/- 2% to 5% RH+/- 2% RH+/- 3% RH+/- 2% RH
Sampling Rate1 Hz (once per second)0.5 Hz (once per 2 seconds)Up to 1 Hz recommendedUp to 157 Hz (low power mode)Up to 10 Hz
Extra FeaturesVery cheapLong cable toleranceCompact sizeBarometric pressureInternal condensation heater

Wiring Connections

The example sketch below reads the BME280 over the I2C bus on an Arduino Uno, as it demonstrates modern I2C sensor interfacing alongside pressure altitude estimation.

BME280 Breakout to Arduino Uno

PinArduino PinFunction
VCC5V (or 3.3V if no onboard regulator)Powers the sensor breakout board
GNDGNDCommon ground reference
SCLA5 (SCL)I2C serial clock line
SDAA4 (SDA)I2C serial data line

Pin labels and ordering vary across third-party breakout boards (VCC, GND, SCL, SDA versus VIN, GND, SCK, SDI), so always inspect the silkscreen printing on your specific PCB before applying power.

Complete Code

Arduino Uno sketch to read temperature, relative humidity, and barometric pressure from a BME280 sensor over I2C and display a simple comfort status.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Standard sea-level pressure in hPa for altitude estimation
#define SEALEVELPRESSURE_HPA (1013.25)

// Create BME280 I2C object
Adafruit_BME280 bme;

// Default I2C address is 0x76 on most generic modules (0x77 on Adafruit boards)
const uint8_t BME280_I2C_ADDR = 0x76;

// Read interval in milliseconds (2000 ms avoids self-heating)
const unsigned long READ_INTERVAL_MS = 2000;
unsigned long previousMillis = 0;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    // Wait for serial port connection
  }

  Serial.println("Initializing BME280 Sensor...");

  if (!bme.begin(BME280_I2C_ADDR)) {
    Serial.println("Error: Could not find a valid BME280 sensor.");
    Serial.println("Check wiring or try changing BME280_I2C_ADDR to 0x77.");
    while (1) {
      delay(100);
    }
  }

  Serial.println("BME280 initialized successfully.");
  Serial.println("----------------------------------------");
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= READ_INTERVAL_MS) {
    previousMillis = currentMillis;

    float temperatureC = bme.readTemperature();
    float humidityPct = bme.readHumidity();
    float pressureHpa = bme.readPressure() / 100.0F;
    float approxAltitudeM = bme.readAltitude(SEALEVELPRESSURE_HPA);

    Serial.print("Temperature: ");
    Serial.print(temperatureC, 2);
    Serial.println(" C");

    Serial.print("Humidity:    ");
    Serial.print(humidityPct, 2);
    Serial.println(" %");

    Serial.print("Pressure:    ");
    Serial.print(pressureHpa, 2);
    Serial.println(" hPa");

    Serial.print("Altitude:    ");
    Serial.print(approxAltitudeM, 1);
    Serial.println(" m");

    // Simple indoor comfort classification
    if (humidityPct < 30.0) {
      Serial.println("Air Status:  Dry");
    } else if (humidityPct <= 60.0) {
      Serial.println("Air Status:  Comfortable");
    } else {
      Serial.println("Air Status:  Humid");
    }

    Serial.println("----------------------------------------");
  }
}

Uploading and Testing

  1. Open the Arduino IDE and go to Tools > Manage Libraries.
  2. Search for and install Adafruit BME280 Library along with its dependency Adafruit Unified Sensor.
  3. Connect the Arduino Uno to your computer using a USB cable.
  4. Select Arduino Uno under Tools > Board and choose the active serial port under Tools > Port.
  5. Paste the complete code into a new sketch and click Upload.
  6. Open Tools > Serial Monitor and set the baud rate dropdown to 9600.
  7. Verify that temperature, humidity, pressure, and air status print every 2 seconds, then gently breathe near the sensor to watch the humidity reading climb and recover.

How to Choose the Right Sensor

Selecting the best sensor depends on your environment, wiring distance, and accuracy budget rather than buying the most expensive part.

  • Choose the DHT11 for basic learning: Pick it only for indoor classroom exercises above 0 C where +/- 2 C error is acceptable and cost is the top priority.
  • Choose the DHT22 for long cables: Its slower 1-wire timing handles cable runs of several meters better than standard I2C without extra bus buffers, making it handy for simple greenhouse probes.
  • Choose the AHT10 for budget I2C builds: It offers +/- 0.3 C accuracy and I2C convenience at roughly the price of a DHT11, though its fixed 0x38 address prevents putting two AHT10 sensors on the same I2C bus without a multiplexer.
  • Choose the BME280 for weather stations: Whenever you also need barometric pressure for weather forecasting or altitude tracking, the BME280 replaces two separate modules on a single I2C bus.
  • Choose the SHT31 for harsh or high-humidity environments: Its +/- 0.2 C accuracy, 5 V tolerant I2C pins, and built-in heater element prevent dew condensation from ruining readings in outdoor enclosures or incubators.

Note that the provided example sketch targets the BME280 specifically and does not auto-detect DHT11, DHT22, AHT10, or SHT31 sensors, which each require their own dedicated Arduino libraries.

Common Problems

  • Serial Monitor prints "Could not find a valid BME280 sensor": Most generic purple or blue BME280 modules use I2C address 0x76, while Adafruit breakouts default to 0x77. Change BME280_I2C_ADDR to 0x77 or run an I2C scanner sketch to confirm the address.
  • Sensor is actually a BMP280 instead of a BME280: Many low-cost listings sell the BMP280 (which lacks a humidity sensor) in an identical package. Check the tiny metal lid markings; a BME280 has a square casing with a vent hole, whereas a BMP280 is slightly rectangular and reports 0% or NaN for humidity.
  • Temperature reads 1 C to 2 C higher than room temperature: Continuous rapid polling causes internal self-heating inside the sensor package. Keep the read interval at 2000 milliseconds or longer and mount the sensor away from voltage regulators or the Arduino microcontroller.
  • DHT11 or DHT22 returns NaN values: Missing pull-up resistors or polling faster than the sensor recovery window causes failed reads. Add a 4.7 kOhm to 10 kOhm pull-up resistor between DATA and VCC on bare 4-pin sensors and wait at least 2 seconds between DHT22 reads.
  • I2C sensor stops responding over long wires: Standard I2C is designed for short board-to-board connections under 30 cm. Keep SDA and SCL wires short, or lower the I2C clock speed using Wire.setClock(10000); if longer leads are unavoidable.
  • AHT10 conflicts with other I2C devices: The AHT10 uses a fixed 0x38 address and can interfere with certain older I2C devices on the same bus. Isolate it using a TCA9548A I2C multiplexer if you connect multiple sensors.

Summary

In this guide, you compared five widely used temperature and humidity sensors for Arduino (DHT11, DHT22, AHT10, BME280, and SHT31) and built a working I2C environmental monitor using the BME280 and an Arduino Uno. Digital sensors measure capacitance and resistance internally, apply factory calibration, and transmit clean values over 1-Wire or I2C interfaces. By understanding each module's accuracy, voltage limits, and bus requirements, you can confidently select the right sensor for indoor automation, weather stations, or high-precision data logging