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.

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.
- A capacitive humidity sensing element absorbs or releases water vapor from the surrounding air, which changes the electrical capacitance between two microscopic electrodes.
- A thermistor or bandgap temperature sensor measures the ambient temperature by tracking predictable changes in electrical resistance or semiconductor voltage.
- An integrated microcontroller inside the sensor reads both raw signals, applies factory-stored calibration coefficients, and compensates for temperature effects on the humidity reading.
- The sensor sends the final temperature and relative humidity values to the Arduino over either a single-wire proprietary protocol or a standard
I2Cbus.
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.
| Item | Choice | Reason |
|---|---|---|
| Microcontroller | Arduino Uno | Standard 5 V development board with I2C and digital GPIO pins |
| Entry-Level Sensor | DHT11 Module | Low-cost 1-wire sensor for basic indoor classroom demos |
| Mid-Range 1-Wire Sensor | DHT22 (AM2302) | Wider temperature range and better accuracy than DHT11 |
| Budget I2C Sensor | AHT10 Breakout | Fast I2C communication and solid accuracy at a low price |
| Multi-Sensor I2C Breakout | BME280 (3.3 V / 5 V module) | Measures temperature, humidity, and barometric pressure |
| High-Precision I2C Sensor | SHT31-D Breakout | Industrial-grade accuracy, repeatability, and built-in heater |
| Prototyping Gear | Breadboard and jumper wires | Solderless 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.
| Specification | DHT11 | DHT22 (AM2302) | AHT10 | BME280 | SHT31 |
|---|---|---|---|---|---|
| Interface | 1-Wire Proprietary | 1-Wire Proprietary | I2C (0x38) | I2C (0x76 or 0x77) / SPI | I2C (0x44 or 0x45) |
| Operating Voltage | 3.3 V to 5.5 V | 3.3 V to 6 V | 1.8 V to 3.6 V | 1.71 V to 3.6 V (chip) | 2.4 V to 5.5 V |
| Temperature Range | 0 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 Range | 20% to 90% RH | 0% to 100% RH | 0% to 100% RH | 0% to 100% RH | 0% to 100% RH |
| Humidity Accuracy | +/- 5% RH | +/- 2% to 5% RH | +/- 2% RH | +/- 3% RH | +/- 2% RH |
| Sampling Rate | 1 Hz (once per second) | 0.5 Hz (once per 2 seconds) | Up to 1 Hz recommended | Up to 157 Hz (low power mode) | Up to 10 Hz |
| Extra Features | Very cheap | Long cable tolerance | Compact size | Barometric pressure | Internal 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
| Pin | Arduino Pin | Function |
|---|---|---|
VCC | 5V (or 3.3V if no onboard regulator) | Powers the sensor breakout board |
GND | GND | Common ground reference |
SCL | A5 (SCL) | I2C serial clock line |
SDA | A4 (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
#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
- Open the Arduino IDE and go to
Tools > Manage Libraries. - Search for and install Adafruit BME280 Library along with its dependency Adafruit Unified Sensor.
- Connect the Arduino Uno to your computer using a USB cable.
- Select
Arduino UnounderTools > Boardand choose the active serial port underTools > Port. - Paste the complete code into a new sketch and click Upload.
- Open
Tools > Serial Monitorand set the baud rate dropdown to9600. - Verify that temperature, humidity, pressure, and air status print every
2seconds, 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
DHT11for basic learning: Pick it only for indoor classroom exercises above0 Cwhere+/- 2 Cerror is acceptable and cost is the top priority. - Choose the
DHT22for long cables: Its slower 1-wire timing handles cable runs of several meters better than standardI2Cwithout extra bus buffers, making it handy for simple greenhouse probes. - Choose the
AHT10for budgetI2Cbuilds: It offers+/- 0.3 Caccuracy andI2Cconvenience at roughly the price of aDHT11, though its fixed0x38address prevents putting twoAHT10sensors on the sameI2Cbus without a multiplexer. - Choose the
BME280for weather stations: Whenever you also need barometric pressure for weather forecasting or altitude tracking, theBME280replaces two separate modules on a singleI2Cbus. - Choose the
SHT31for harsh or high-humidity environments: Its+/- 0.2 Caccuracy,5 VtolerantI2Cpins, 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
BME280modules useI2Caddress0x76, while Adafruit breakouts default to0x77. ChangeBME280_I2C_ADDRto0x77or run anI2Cscanner 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; aBME280has a square casing with a vent hole, whereas aBMP280is slightly rectangular and reports0%orNaNfor humidity. - Temperature reads
1 Cto2 Chigher than room temperature: Continuous rapid polling causes internal self-heating inside the sensor package. Keep the read interval at2000milliseconds or longer and mount the sensor away from voltage regulators or the Arduino microcontroller. - DHT11 or DHT22 returns
NaNvalues: Missing pull-up resistors or polling faster than the sensor recovery window causes failed reads. Add a4.7 kOhmto10 kOhmpull-up resistor betweenDATAandVCCon bare 4-pin sensors and wait at least2seconds betweenDHT22reads. - I2C sensor stops responding over long wires: Standard
I2Cis designed for short board-to-board connections under30 cm. KeepSDAandSCLwires short, or lower theI2Cclock speed usingWire.setClock(10000);if longer leads are unavoidable. - AHT10 conflicts with other I2C devices: The
AHT10uses a fixed0x38address and can interfere with certain olderI2Cdevices on the same bus. Isolate it using aTCA9548AI2Cmultiplexer 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