Projects / Humidity sensor calibration with salts

Humidity sensor calibration with salts

Saturated salt solutions in sealed jars give known humidity levels to check your sensors.

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Make the saturated solution

    Salt in a little water, with undissolved salt left.

  2. NANO

    Wire the three sensors

    Check each one reads.

  3. NANO

    Seal them in the jar

    Above the liquid.

  4. NANOSHT31AHT2028.0°C

    Wait a day

    Steady room temperature.

  5. NANO

    Read the averages

    Note the offsets.

  6. NANO

    Repeat with a second salt

    Check the slope.

  7. NANO

    Apply the offsets

    In your sensor code.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
SHT31 and AHT20 SDA, SCLNano A4, A5Shared I2C bus (addresses 0x44 and 0x38)
SHT31 and AHT20 VCC and GNDNano 3V3 and GNDPower
DHT22 dataNano D2, with 10 k to 5VSensor signal
DHT22 VCC and GNDNano 5V and GNDPower

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.

CheckExpected
Open airAll three sensors roughly agree
Sealed over salt, after a dayNear 75 percent
OffsetsSmall and steady
Second saltNear 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 →

Ask Lark AI

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.