Capacitive Soil Sensor Wrong Readings

I have a capacitive soil moisture sensor in water, with gnd to gnd, vcc to 3.3v and auot to A0 running this code (arduino uno):

void setup() {
  // Initialize serial communication
  const int moisturePin=A0;
  Serial.begin(9600);
  
  // Set pin mode
  pinMode(moisturePin, INPUT);
}

void loop() {
  // Read soil moisture
  int moistureValue = analogRead(moisturePin);
  
  // Print moisture value to serial monitor
  Serial.print("Moisture Value: ");
  Serial.println(moistureValue);
  
  // Delay for stability
  delay(100);
}

but i keep getting this:


(expected value 1023)

you declare moisturePin in setup(). As soon as setup finishes moisturePin goes out of scope and thereafter does not exist in loop().

Declare moisturePin of global scope.

Code does not compile. is that the right code?

What soil sensors? Will you post a schematic?

...and I'd add one more question: why the expected value must be 1023?

With your sensor connected to 3.3V, the highest value your sensor could read would be: 675

5V / 1023 = 0.004887586 ...... 3.3V / 0.004887586 = 675.

But as water has some resistivity and the sensor has a 10K resistor,
then the value read by your sensor must be correct.

Since your sensor read 322, .... 322 * 0.004887586 = ~1.57V
Therefore, water must have approximately 10k resistance.

image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.