Humidity sensor calibration with salts
Saturated salt solutions in sealed jars give known humidity levels to check your sensors.
Build it step by step
0 of 7 doneMake the saturated solution
Salt in a little water, with undissolved salt left.
Wire the three sensors
Check each one reads.
Seal them in the jar
Above the liquid.
Wait a day
Steady room temperature.
Read the averages
Note the offsets.
Repeat with a second salt
Check the slope.
Apply the offsets
In your sensor code.
How do you build a humidity sensor calibration with salts?
Saturated salt solutions in sealed jars give known humidity levels to check your sensors. You need Arduino Nano, SHT31 temperature and humidity sensor, DHT22 Sensor, AHT20 temperature and humidity sensor and Resistor 10 kΩ. It takes 7 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 5
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SensorsBuyDHT22 Sensor × 1
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| SHT31 and AHT20 SDA, SCL | Nano A4, A5 | Shared I2C bus (addresses 0x44 and 0x38) |
| SHT31 and AHT20 VCC and GND | Nano 3V3 and GND | Power |
| DHT22 data | Nano D2, with 10 k to 5V | Sensor signal |
| DHT22 VCC and GND | Nano 5V and GND | Power |
Code
A sealed jar holding a saturated salt solution settles to a very exact humidity, which depends only on the salt and the temperature: about 75 percent over table salt and about 33 percent over magnesium chloride at room temperature. That gives you a reference no cheap sensor can fake. Put the sensors in the jar, above the liquid and not touching it, seal it, and leave it for a day at a steady temperature, because the air takes hours to settle. The sketch averages the last thirty readings and shows how far each sensor is from the reference, and that offset is what you add in your own code. Use two salts and you can check whether the error is the same at both ends, which tells you whether an offset or a slope is needed. Keep the sensors out of the liquid, since salt solution corrodes them, and wash your hands after handling magnesium chloride. Keep the jar out of sun and drafts, because temperature changes the reference. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Humidity calibration: reads three sensors in the same jar, averages the last 30 readings and shows each sensor's offset from the reference.
// Libraries: Adafruit SHT31, Adafruit AHTX0, DHT sensor library. Board: Arduino Nano.
// Salt references at about 25 C: table salt (sodium chloride) 75 percent, magnesium chloride 33 percent.
#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_AHTX0.h>
#include <DHT.h>
Adafruit_SHT31 sht;
Adafruit_AHTX0 aht;
DHT dht(2, DHT22);
const float REFERENCE_RH = 75.3; // change to 32.8 for the magnesium chloride jar
const int N = 30;
float hs[N], ha[N], hd[N]; int count = 0, idx = 0;
float avg(float* a) { float s = 0; for (int i = 0; i < count; i++) s += a[i]; return count ? s / count : 0; }
void setup() {
Serial.begin(115200);
sht.begin(0x44); aht.begin(); dht.begin();
Serial.println("Seal the sensors in the jar with the salt solution for a day, then read the offsets.");
}
void loop() {
sensors_event_t h, t;
aht.getEvent(&h, &t);
hs[idx] = sht.readHumidity(); ha[idx] = h.relative_humidity; hd[idx] = dht.readHumidity();
idx = (idx + 1) % N; if (count < N) count++;
float s = avg(hs), a = avg(ha), d = avg(hd);
Serial.print("SHT31 "); Serial.print(s, 1); Serial.print(" offset "); Serial.print(REFERENCE_RH - s, 1);
Serial.print(" | AHT20 "); Serial.print(a, 1); Serial.print(" offset "); Serial.print(REFERENCE_RH - a, 1);
Serial.print(" | DHT22 "); Serial.print(d, 1); Serial.print(" offset "); Serial.println(REFERENCE_RH - d, 1);
delay(10000);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Seal the sensors in the jar with the salt solution for a day, then read the offsets. SHT31 0.0 offset 75.3 | AHT20 0.0 offset 75.3 | DHT22 55.0 offset 20.3
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Open air | All three sensors roughly agree |
| Sealed over salt, after a day | Near 75 percent |
| Offsets | Small and steady |
| Second salt | Near 33 percent |
If it does not work
Readings keep drifting
Wait longer and keep the jar still.
Wild difference
Check the sensor is not touching the liquid.
Jar reads lower
Add a little water and make sure salt remains.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the humidity sensor calibration with salts?
Arduino Nano, SHT31 temperature and humidity sensor, DHT22 Sensor, AHT20 temperature and humidity sensor and Resistor 10 kΩ.
How long does the humidity sensor calibration with salts take to build?
About 180 minutes for a intermediate maker, in 7 steps.
How do I know the humidity sensor calibration with salts works?
Open air: All three sensors roughly agree. Sealed over salt, after a day: Near 75 percent. Offsets: Small and steady.
Readings keep drifting: what should I check?
Wait longer and keep the jar still.
Wild difference: what should I check?
Check the sensor is not touching the liquid.
Jar reads lower: what should I check?
Add a little water and make sure salt remains.
