Soil moisture capacitive sensor - slow response

Hello guys,

I'm quite new with Arduino, but I have some programing knowledge.
I bought this soil moisture sensor:
https://www.aliexpress.com/item/Analog-Capacitive-Soil-Moisture-Sensor-V1-2-Corrosion-Resistant-Z09-Drop-ship/32858273308.html

I used this basic code:
void setup() {
Serial.begin(9600);
}
void loop() {
int val;
val = analogRead(0);
Serial.print(val);
delay(100);
}

and my readings are very slow. If I put it in water it takes almost 30-40 seconds to get down from a value of 611 to ~240, while this guy get almost instant readings:

Even with his code I have the same slow response!

Can you help me please to understand why and how to fix it? or to find one that is anti corrosion?!

Thank you for your time,
all the best!

I'm facing same issue. Would be great if someone can enlighten us

martinel91:
Hello guys,

I'm quite new with Arduino, but I have some programing knowledge.
I bought this soil moisture sensor:
https://www.aliexpress.com/item/Analog-Capacitive-Soil-Moisture-Sensor-V1-2-Corrosion-Resistant-Z09-Drop-ship/32858273308.html

I used this basic code:
void setup() {
Serial.begin(9600);
}
void loop() {
int val;
val = analogRead(0);
Serial.print(val);
delay(100);
}

and my readings are very slow. If I put it in water it takes almost 30-40 seconds to get down from a value of 611 to ~240, while this guy get almost instant readings:
https://www.youtube.com/watch?v=29AB8KrGSdU

Even with his code I have the same slow response!

Can you help me please to understand why and how to fix it? or to find one that is anti corrosion?!

Thank you for your time,
all the best!

Hi,

I think I manage to find a workaround:

1 ) I noticed that the reading gets update immediately ( i.e reading goes down from 600++ to 300 ++) - if I
disconnect and reconnect the ground from sensor from arduino (breaking and closing the circuit loop from sensor to Arduino).
Emulating the same setup on 5V power doesnt work ( not sure why)

  1. I used a C1815Y npn transistor to emulate this. connect the collector pin to ground from sensor and emitter pin to ground in Arduino.
    And the connect the base to a digital pin with a 1K resistor.

  2. Modify the code to have digital pin always on high on startup (digitalWrite(8, HIGH);). In that way, the ground from sensor (C) is
    always connected to ground in arduino (C). Low the digital output for 500 ms before make it high again. When you low the digital
    pin,there is no current flow from C to E - the ground connection is open -and thus it is as if we removed the ground and reconnect

Please do share if there is other simpler alternative.

Cheers

vj

int moistureSensorValue1;
int moistureSensorPin1 = A0; //Analog pin1
int reset = 8;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(reset, OUTPUT);
digitalWrite(reset, HIGH);
}

void loop() {
// put your main code here, to run repeatedly:
moistureSensorValue1 = analogRead(moistureSensorPin1);

Serial.println(moistureSensorValue1);
digitalWrite(reset, LOW);
delay(500);
digitalWrite(reset, HIGH);
delay(500);

}

hmmm, that doesnt sounds the right way,
what I saw is when I'm using the measuring device to read the Analog output from the sensor, the readings are instant,
so, if I'm right, the measuring device has a resistance (I don't know how big), so I put a 1M ohm resistor between the sensor analog output pin and GND ground pin from Arduino, and now I get instant readings with voltages registered between 0.95V and 2.65V
I don't know if this is the solution, but now I get instant readings
it will be nice if there is someone who can help us

P.S.: sorry for my bad english

Hey guys, I had the same issue and thanks to you I could manage it!

You can simply just switch the GND pin of the sensor by connecting it to a digital output on the Arduino itself.

Heres part of the code I use:

  lcd.setCursor(0,2);
  digitalWrite(6,LOW); // Pin I use for switching GND of the sensor ON
  delay(500);              // delay necessary here for giving it time to read
  soil=analogRead(A0);
  lcd.print(soil);
  
  digitalWrite(6,HIGH); // switch the probe OFF

Hi guys, and thanks Floduino for the trick, my side i have to had one more delay to make it work properly :

void setup() {
Serial.begin(9600);
pinMode(6,OUTPUT);
}
void loop() {
int val;
digitalWrite(6,LOW); // Pin I use for switching GND of the sensor ON
delay(200); // delay necessary here for giving it time to read
val = analogRead(0); //connect sensor to Analog 0
Serial.println(val); //print the value to serial port
digitalWrite(6,HIGH); // switch the probe OFF
delay(200);
}

You are right, it worked for me for most of the time but now it stoped working properly.

I addet the second delay and now its working fine again!

Thank you bro!

hey i had the same issue and reverse engineered the sensor. i think it´s a problem with the layout of the sensor pcb. the resistor R4 with 1M Ohm should discharge the output capacitor of the analog output. but there is no connection from R4 to GND. in fact there is no connection at all to anywhere on the pcb.

i soldered a wire from R4 to GND and it seems to work just fine now.

hope this helps:)

1 Like

roborob:
hey i had the same issue and reverse engineered the sensor. i think it´s a problem with the layout of the sensor pcb. the resistor R4 with 1M Ohm should discharge the output capacitor of the analog output. but there is no connection from R4 to GND. in fact there is no connection at all to anywhere on the pcb.

i soldered a wire from R4 to GND and it seems to work just fine now.

hope this helps:)

I saw that R4 resistor is connected with AOUT pin

1 Like

Robrob you are correct.
No need to change the code to add the digital input etc.
The PCB has a flaw, the R4(1Mohm) resistor is not connected to the ground, solder a small piece of wire (the side facing the connector) to connect it to the ground and it works fine.

This is a known issue with some versions of this board.
There is an explanation and some solutions here:

https://www.so-now.com/electronics/capsense.php