Sub topic 11
Accuracy Limits and Calibration Offsets
Assume you can wire a DHT11 or DHT22, install the Adafruit DHT library, and read values from an Arduino sketch. This chapter focuses on how much you can trust those values and how to correct a consistent measurement error.
Accuracy, resolution, and repeatability
Accuracy describes how close a reading is to the true value. Resolution describes the smallest displayed change. A sensor might display temperature to one decimal place while still being wrong by half a degree.
Repeatability describes whether the sensor gives nearly the same result when the same conditions remain unchanged. A repeatable sensor can still be inaccurate if it has a fixed offset.
Typical DHT specifications are approximate:
| Sensor | Temperature accuracy | Relative humidity accuracy | Typical use |
|---|---|---|---|
| DHT11 | about ±2 °C | about ±5% RH | Basic demonstrations |
| DHT22 | about ±0.5 °C | about ±2–5% RH | General indoor monitoring |
Check the datasheet for your exact sensor. Clone modules, wiring, airflow, and operating conditions can produce different results.
Relative humidity, written as RH, is the amount of water vapor in air compared with the maximum amount the air can hold at that temperature. Because warm air can hold more water vapor, RH changes when temperature changes even if the amount of water vapor stays constant. A humidity reading is therefore meaningful only when the sensor temperature is also considered.
Measure before applying an offset
Calibration means comparing a sensor with a trusted reference and using the comparison to reduce error. For a simple offset calibration:
- Place the DHT sensor and reference instrument close together.
- Keep them away from sunlight, heating elements, and direct drafts.
- Wait until both readings stabilize.
- Record several pairs of readings.
- Calculate the average difference.
For example, if the reference reports 22.0 °C and the DHT22 reports 22.6 °C, the temperature offset is -0.6 °C. Add this offset to later raw readings.
An offset corrects a consistent error. It does not correct errors that change with temperature or humidity. It also cannot improve a sensor's response time, resolution, or long-term drift.
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const float TEMP_OFFSET_C = -0.6;
const float HUMIDITY_OFFSET = 1.5;
float calibratedTemperature(float rawC) {
return rawC + TEMP_OFFSET_C;
}
float calibratedHumidity(float rawPercent) {
return constrain(rawPercent + HUMIDITY_OFFSET, 0.0, 100.0);
}
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000);
float rawHumidity = dht.readHumidity();
float rawTemperatureC = dht.readTemperature();
if (isnan(rawHumidity) || isnan(rawTemperatureC)) {
Serial.println(F("Sensor read failed"));
return;
}
float temperatureC = calibratedTemperature(rawTemperatureC);
float humidity = calibratedHumidity(rawHumidity);
Serial.print(F("Temperature: "));
Serial.print(temperatureC, 1);
Serial.print(F(" C, Humidity: "));
Serial.print(humidity, 1);
Serial.println(F(" % RH"));
}The humidity offset is also measured as a percentage-point difference. If the reference reports 48% RH and the sensor reports 46.5% RH, add 1.5 to the raw result. This is different from adding 1.5 percent of the reading.
Limits and placement
Do not calibrate against a cheap reference with unknown accuracy. For better results, use a reference instrument whose accuracy is documented.
The sensor can read incorrectly when:
- It is touched or warmed by your fingers.
- It is enclosed without enough air exchange.
- It is placed near the Arduino's voltage regulator.
- Condensation forms on the sensing element.
- The supply voltage is incorrect.
- The sensor is read more often than its minimum sampling interval.
Store calibration offsets as constants and document the reference, date, and conditions used to obtain them. Recheck the calibration if the sensor is moved, aged, or exposed to condensation.
Exercise
A reference shows 50% RH, while the DHT sensor shows 47%. What humidity offset should the sketch add?
Show answer
Add 3 percentage points. The calibrated result is the raw reading plus 3.0, limited to the valid range of 0% to 100% RH.