Random ADC offset

Hi, I use a capacitive moisture sensor to read the moisture levels of a plant. I want to use it to automatically water the plant when needed. The “dry” value seems to be around 400, while the “wet” value is anywhere below 350, but typically around 320.

However, as can be seen in the attachment, at one point the value makes a discrete, very sudden jump from around 375 to 500. At this point the Arduino was reset. The second jump from 475 to 375 was after another reset.
So it seems that the ADC of the Arduino (I use a pro mini 5v 16Mhz) seems to have a random offset.

Any idea how to prevent such a jump from occurring, or perhaps an explanation why this is happening?

moisture.png

Hi, I use a capacitive moisture sensor to read the moisture levels of a plant. I want to use it to automatically water the plant when needed. The "dry" value seems to be around 400, while the "wet" value is anywhere below 350, but typically around 320.

To recapture that: the difference between dry and wet is about 40mV.

However, as can be seen in the attachment, at one point the value makes a discrete, very sudden jump from around 375 to 500. At this point the Arduino was reset. The second jump from 475 to 375 was after another reset.
So it seems that the ADC of the Arduino (I use a pro mini 5v 16Mhz) seems to have a random offset.

Using standard sketches (you didn't post your code) such offsets are explained easily: A change in the supply voltage which affects also the ADC reading.

As you didn't post a link to the sensor used, nor a wiring diagram of your setup, my conclusion is even much easier: it's either a hardware or a software problem as we haven't seen any of it.

pylon:
To recapture that: the difference between dry and wet is about 40mV.

(400 - 320) / 1024 * 5V = 0.39V or 400 mV

Here is a link to the sensor: Capacitive Soil Moisture Sensor Module Not Easy to Corrode Wide Voltage Wire 3.3~5.5V Corrosion Resistant W/ Gravity for Arduino|Sensors| - AliExpress

And here is the code:

void setup() {
  pinMode(A1, INPUT);
  Serial.begin(9600);
}

void loop() {
  int value = analogRead(A1);
  Serial.println(value);
  delay(1000);
}

The wiring is obvious. The sensor pin goes to A1, the 5V and GND to the respective pins on the Arduino. And the Arduino is connected by USB to the PC.

perhaps an explanation why this is happening?

Bad connection somewhere, or defective sensor.

If you browse through this and other forums, you will find that your experience is typical. Most people who experiment with cheap soil moisture sensors give up after a while.

If I read correctly, you are experiencing a spike after a reset, sort of like an instability on the first few readings. You can pick a count, and ignore the readings whiles the number of readings is under a preset count. You can, also, delay the time from restart to when the first readings are taken. You can also take the readings and average them which would allow the readings to ramp up and to be a bit smoother on the transitions.

Though, jremington, is correct about most people giving up on the cheap sensors, after a while.

Idahowalker:
If I read correctly, you are experiencing a spike after a reset

No, unfortunately not. It is an offset on the data. You can see it in the graph in the attachment.

3cHeLoN:
No, unfortunately not. It is an offset on the data. You can see it in the graph in the attachment.

I am a so so programmer and electronic person. Would you, not knowing me, open a package I created?

OP's picture, posted properly:
moisture.png

It is an offset on the data.

I see large and small spikes in the data, plus substantial background drift (in both directions) and shifts. Utterly worthless.

Thanks for posting the plot. I wouldn't say it's worthless. The small spikes can easily be filtered with a low-pass filter, or even a running average. From 2019-03-21 to 2019-04-05 there is a clear pattern: 1) plant gets water, the value drops steeply; 2) the value has a plateau (wet phase); 3) the value starts to increase, corresponding to drying out over a period of two weeks. But the jump to 500 is what worries me. There is no way you can easily set a threshold that indicates a dry plant if there are so large jumps.

The rest of the graph is consistent again. At 2019-04-11 I gave the plant way too much water, which is why the value drops very fast (I had a rounding error in my watering time :), I use a pump to give water when needed).

You get a good drying out curve. You can figure out the rate of drying out of the soil, confirm it with readings, and ignore readings over 400, staying with the predicated drying curve instead as a solution till the issue is found out.

You could also use another sensor to confirm the readings of the first sensor. Using the sensor that gives the readings nearest to the predicated curve.

You could add a 2nd sensor, like a humidity sensor, near the plant and use humidity as a secondary confirmation sensor.

My suspicion is that the sensor is unusable... Perhaps the reset cycle causes the sensor to change its calibration vastly? That's what it looks like.