Page 1 of 1

Two-point sensor calibration in code, is this the right approach?

Posted: Wed Jul 08, 2026 8:00 am
by sam_python
Coming from software. My analog soil moisture sensor reads raw ADC (0-4095), but I need % moisture. Calibration confuses me.

What I did:
  • Dry sensor in air: reads ~3200 (call this 0%)
  • Sensor in water: reads ~1400 (call this 100%)
  • Linear map: percent = (3200 - raw) / (3200 - 1400) * 100

Code: Select all

def moisture_pct(raw):
    dry, wet = 3200, 1400
    pct = (dry - raw) / (dry - wet) * 100
    return max(0, min(100, pct))
Works roughly. But soil is not water, so 100%=submerged is not realistic field max.

Sensor/calibration folks: is two-point linear enough, or do these sensors need curve fitting? Should I calibrate against actual soil samples, not water?