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)
-
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.
-
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);
}