I am developing a system that can monitor a set of parameters (temperature, air humidity and soil moisture level) to be transmitted once per hour to an online server. This system is based on a Lilygo TTGO T-CALL board, as I needed GPRS capabilities.

This is the sensor that I am using for measuring soil moisture, as it seems to be more durable than the resistive ones. enter image description here

Here is the portion of code that measures values from the sensor:

for(int i = 0; i < MEASUREMENTS; i++) {

  SerialMon.print("[LOOP] Measurement number ");
  // Compute soil moisture value
  soil_moisture_val = analogRead(SOILSENS);
  soil_moisture_percent[i] = map(soil_moisture_val, air_moisture, water_moisture, 0, 100);

  // Cut values exceeding bounds
  if(soil_moisture_percent[i] > 100)
    soil_moisture_percent[i] = 100;
  else if(soil_moisture_percent[i] < 0)
    soil_moisture_percent[i] = 0;

  // Sleep for 4 seconds

The sensor is connected to 3v3 and GND pins and the AOUT pin goes to pin 34 (SOILSENS in the code snippet). After taking and transmitting measurements, the board goes to sleep but the sensor stays powered on as supply lines are not affected by the deep sleep. The problem I am seeing is a constant upwards drift of the measured value by the sensor: after a few hours of usage, the soil moisture value read by the sensor increases by some percentage points, e.g., I started the system yesterday evening with a reading of 14.4% and I now have almost 18%.

I am at a loss, the code seems alright, I make sure to insert the sensor properly (not going past the white line) and I haven't watered any of my plants. Is there something I am missing, or is this just a bad batch of sensors? If so, do you have a recommendation for something more reliable with a similar functioning (analog output value)?

  • \$\begingroup\$ One way to test whether the drift is due to the sensor or not is to put some water in a glass. Dry the sensor and then hang it above the water with its length partially dipped. Measure the moisture for a day. If the reading is drifting away, then you know the sensor is unreliable. \$\endgroup\$
    – kaosad
    Commented Feb 7 at 8:46
  • \$\begingroup\$ Are "air_moisture" and "water_moisture" fixed values? \$\endgroup\$
    – JRE
    Commented Feb 7 at 11:43
  • \$\begingroup\$ @kaosad, I will try this method thank you! JRE, yes those are fixed values I measured with the same sensor. \$\endgroup\$ Commented Feb 7 at 19:27

1 Answer 1


Are you sure there's really a problem at all?

Soil moisture isn't a fixed value - it does vary over the course of the day.

I have an on-going project that monitors the soil moisture in the flower garden in front of my house. The soil moisture varies considerably over the course of the day. A few percentage points a day up and down is completely normal:

enter image description here

That's a view of the soil moisture over a period of 30 days, measured once per hour. During the early part, the moisture is between 50 and 52 percent with daily drops down to 30 percent at noon time. We then got some rain, and the moisture stayed above 58 percent for the rest of the month. Even there, you can see daily variations of several percent.

Another thing to consider is that when you put the sensor in the dirt, there will be gaps between the sensor prongs and the dirt. These gaps will cause the moisture readings to be a bit low. As the dirt settles and the gaps go away the moisture readings will go up a bit. Dry dirt is more prone to gaps - and your dirt looks to be fairly dry at 18%.

I'd let the sensors run a couple of days and log all the data. There might be no problem (natural variation over the course of the day) or there might be a systematic problem with your sensors.

I had a closer look at the picture of your sensor. It uses a 7555 CMOS timer IC to do the moisture measurements. A variation of a few percent a day wouldn't surprise me at all.

Log the data for a few days and see what you get.

Keep in mind that what you'll be looking at are trends, not absolute cutoffs. It's not like the plants are going to be fine at, say, 20% moisture then croak when it drops to 19%.

  • \$\begingroup\$ Thank you very much for your reply. Since I got three sensors, I tried using another one and the values seem to be more stable. I agree that the point here is identifying a range of values (dry, moist, wet) rather than the precise number, however with the sensor I was mentioning, in a previous round of measurements I observed a 22% that got to 35% in two days. That got me thinking that something may have been off, as this 13% increase is more than what I believe a reasonable adjustment would be. I will however let it run for a few days and look for the trend data shows \$\endgroup\$ Commented Feb 7 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.