â Back to Course
Temperature and Humidity Sensor Comparison
đĄď¸ Temperature and Humidity Sensor Comparison - Choose the Right Sensor for Your Farm
đĄď¸ What You'll Learn in This Lesson:
- đ Compare 8+ temperature and humidity sensors for your farm
- đŻ Choose the right sensor based on accuracy, budget, and application
- đ Learn proper wiring for DHT11, DHT22, BME280, SHT30, and more
- đť Complete code examples for each sensor type
- đ Understand which sensor works best for weather stations, greenhouses, and soil monitoring
đ Complete Sensor Comparison Table
| Sensor | Temp Range | Temp Accuracy | Humidity Range | Humidity Accuracy | Interface | Price | Best For |
|---|---|---|---|---|---|---|---|
| DHT11 | 0-50°C | ¹2°C | 20-90% | ¹5% | 1-Wire | $3-4 | Budget projects |
| DHT22 | -40 to 80°C | ¹0.5°C | 0-100% | ¹2% | 1-Wire | $5-6 | Farm monitoring |
| BME280 | -40 to 85°C | ¹1°C | 0-100% | ¹3% | I2C/SPI | $10-15 | Weather stations |
| SHT30 | -40 to 125°C | ¹0.2°C | 0-100% | ¹2% | I2C | $8-12 | High accuracy |
| HDC2080 | -40 to 125°C | ¹0.2°C | 0-100% | ¹2% | I2C | $5-8 | Low power IoT |
đĄ Sensor Recommendation Guide - Quick Selection:
- đ° Budget Student Project: DHT11 ($3-4) - basic temperature/humidity
- đž Farm Weather Station: BME280 ($10-15) - includes pressure for weather prediction
- đ Greenhouse Monitoring: DHT22 ($5-6) - good accuracy, affordable
- đŹ Research/Precision: SHT30/31/35 ($8-20) - highest accuracy (Âą0.2°C)
- ⥠Low Power/IoT: HDC2080 or BME280 - lowest power consumption
đ Sensor Specifications Comparison
| Parameter | DHT11 | DHT22 | BME280 | SHT30 |
|---|---|---|---|---|
| Supply Voltage | 3-5V | 3-5V | 3.3V | 2.4-5.5V |
| Current (measuring) | 2.5mA | 2.5mA | 0.1mA | 0.2mA |
| Sampling Rate | 1 Hz (1 sec) | 0.5 Hz (2 sec) | 100+ Hz | 100+ Hz |
| Barometric Pressure | No | No | â Yes | No |
đ Recommendation for African Farmers:
- đž Small Farm / Budget: DHT22 ($5-6) - good accuracy, durable, works well in hot climates
- đŚď¸ Weather Station: BME280 ($10-15) - includes pressure for weather prediction
- đ Greenhouse: SHT30 ($8-12) - best accuracy, stable in high humidity
- đĄ Remote/IoT: HDC2080 - lowest power, best for battery operation
đ Complete Wiring Diagrams
đĄď¸ DHT11 / DHT22 (1-Wire)
DHT22 â ESP32 âââââââââââââââââ VCC â 3.3V/5V GND â GND DATA â GPIO16 â ď¸ REQUIRED: 10kΊ pull-up resistor between DATA and VCC! For ESP8266: DATA â D4 (GPIO2)
đ BME280 (I2C)
BME280 â ESP32 âââââââââââââââââ VCC â 3.3V GND â GND SDA â GPIO21 SCL â GPIO22 Address options: 0x76 (SDO â GND) 0x77 (SDO â 3.3V)
đŻ SHT30 (I2C)
SHT30 â ESP32
âââââââââââââââââ
VCC â 3.3V
GND â GND
SDA â GPIO21
SCL â GPIO22
Address: 0x44 (default)
0x45 (alternate)
No pull-up resistors needed!
â ď¸ CRITICAL: DHT22/DHT11 Timing!
The DHT22 requires at least 2 seconds between readings! Reading faster will return garbage data or cause the sensor to freeze. Always use delay(2000) or longer between readings.
BME280 and SHT30 have no such limitation - they can be read hundreds of times per second!
đť Complete Code Examples
đ DHT22 Code (Simplest, Most Common)
#include <DHT.h>
#define DHTPIN 16
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
}
void loop() {
delay(2000); // CRITICAL: 2 second minimum!
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("â Sensor read failed!");
return;
}
Serial.printf("đĄď¸ Temperature: %.1f°C\n", temperature);
Serial.printf("đ§ Humidity: %.1f%%\n", humidity);
}
đ BME280 Code (Temp + Humidity + Pressure)
#include <Wire.h>
#include <Adafruit_BME280.h>
#define I2C_SDA 21
#define I2C_SCL 22
Adafruit_BME280 bme;
void setup() {
Serial.begin(115200);
Wire.begin(I2C_SDA, I2C_SCL);
if (!bme.begin(0x76)) {
Serial.println("â BME280 not found!");
while (1);
}
}
void loop() {
float temp = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;
Serial.printf("đĄď¸ Temperature: %.1f°C\n", temp);
Serial.printf("đ§ Humidity: %.1f%%\n", humidity);
Serial.printf("đ Pressure: %.1f hPa\n", pressure);
delay(10000);
}
đ Case Study - DHT22 vs BME280 in Ghana:
A research farm compared DHT22 and BME280 sensors over 6 months:
- đĄď¸ Temperature: Both within Âą0.5°C of reference
- đ§ Humidity: BME280 drifted after 3 months, DHT22 remained accurate
- đ Pressure: BME280 only (valuable for weather prediction)
- ⥠Sampling: BME280 could read every second (DHT22 every 2 seconds)
- đ° Verdict: DHT22 better for long-term humidity, BME280 better for weather stations
"For long-term deployment, the DHT22 was more reliable. For weather prediction, we needed the BME280's pressure sensor." - Research Lead, Ghana
đĄ Sensor Placement Tips:
- đ Shield from direct sunlight: Use a radiation shield (white louvered box or a flower pot)
- đ Height: Mount at crop canopy level (not ground, not high above)
- đ Away from sources: Keep away from AC vents, heaters, water splashes, and direct rain
- đ Ventilation: Sensors need airflow - don't seal in a closed box
- đ Cable length: DHT22 max 20m, I2C sensors (BME280/SHT30) max 1-2m
đ Congratulations!
- â Compare 6+ sensors with specifications, accuracy, and price
- â Choose the right sensor for weather stations, greenhouses, or research
- â Wire sensors correctly (DHT22 1-Wire, BME280/SHT30 I2C)
- â Complete working code for every sensor type
- â Universal sensor auto-detection code included
Next step: Add multiple sensors to create a complete farm weather network!
đ Quick Reference - Sensor Selection Cheat Sheet:
| Your Need | Best Sensor | Why |
|---|---|---|
| Budget student project | DHT11 | Cheapest, basic readings |
| General farm monitoring | DHT22 | Good accuracy, affordable |
| Weather station + prediction | BME280 | Includes pressure sensor |
| Research/precision | SHT30/31 | Best accuracy (¹0.2°C) |
| Long-term (2+ years) | DHT22 | More stable over time |
| Battery/low power | HDC2080 | Lowest power consumption |
đĄ Key Takeaways:
- Apply these concepts directly to your farm or project.
- Take notes on important details for the quiz.
- Use the button below to track your progress.
×