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))Sensor/calibration folks: is two-point linear enough, or do these sensors need curve fitting? Should I calibrate against actual soil samples, not water?