Making Sense of Moisture Sensor Readings

I am working on my 8th grade STEM fair project right now. I am trying to make an automatic plant watering system that will allow you to still have your plant be watered even when you are away from home. I have everything setup and connected right now and the code below is what I've written to test reading the capacitive moisture sensor:

int moistSensorPin = A1;
int soilMoistureValue = 0;

void setup() 
{
  Serial.begin(9600);              // open serial port, set the baud rate to 9600 bps
  pinMode(moistSensorPin, INPUT);  // Pin used to read signal from moisture sensor
  delay(3000);
}

void loop() 
{
  soilMoistureValue = analogRead(moistSensorPin);  //read Sensor inserted into soil
  Serial.print("Moisture sensor reading: ");
  Serial.println(soilMoistureValue);
  delay(1000);  
}

I am having issues however because I keep getting the same numbers (soilMoistureValue ) from the Arduino no matter if the moisture sensor is in water or air or soil, and no matter what port I set to read the capacitive moisture sensor, for example A0 vs A1 vs A2. All are giving me the same readings (155-162) , even when nothing is connected to those ports. I've confirmed that the moisture sensor gives variable output voltages: 0.83v in water and 2.20v in air.

I'm using IDE 2.3.6, Arduino Nano Connect RP2040 and Windows 11 Home 24H2.

I am hoping someone could help me and see if there is something wrong with my code or what is wrong with my connections or setup.

Thanks

What sensor do you have, and from where did you buy it?

Can you post a picture of your project and links to technical information on the sensor?

You probably need to make some sort of adjustment to accommodate the sensor resolution to the analog pin resolution. I have a vague memory that is needed, but I don't remember how. I would check the LRM.

Sensor details - all the package says is Gikfun Capacitive Soil...IV. The probe itself says Capacitive Soil Moisture Sensor v1.2 It is described and pictured here: Interface Capacitive Soil moisture sensor v1.2 with Arduino, LCD and OLED – Circuit Schools
I bought it off Amazon: Amazon.com: Gikfun Capacitive Soil Moisture Sensor Corrosion Resistant for Arduino Moisture Detection Garden Watering DIY (Pack of 2PCS) EK1940 : Patio, Lawn & Garden


Sensor is at bottom of photo. Arduino Nano Connect in a Screw Terminal adapter in center. Relay and small pump to the right and USB for 5v power at top right.

Ḯ'm a bit biased from watching this vid (starts where he discuss what different kind of issues there is with the ones he bought):

If you got a multimeter, see what readings you get if you connect 5 V instead of 3.3 V.

Btw, the sensor you got is different from the one in the pictures @ Amazon.

I tried specifying analogReadResolution() with 10 (default) and it made no difference (still get the same stream of results around 155-162). I tried analogReadResolution() with 12 and it changed it to a stream of values around 660 (about 4 times greater) , but there is no change based on whether the sensor is in air or water. I'm not sure what analogReference() does so I'm reluctant to try it.

I think it has to be 8 but just a hunch.

Wow. Thanks for the video. I am supplying 5V to the sensor board (from a USB brick), confirmed by measuring across the pins. What differences are you seeing between my photo and Amazon?

It's hard to see exactly from your picture, here's a cropped pic of both your sensor and the one from Amazon

Maybe I'm fooled by the light and the blurry pic.

What text can you read from the two IC's U2 and U1?

U2 says 662K. U1 says NE555, then next line is TI logo 21K, and bottom lime says XBL8 G4

the 662k is a 3.3 voltage regulator and a NE555 needs minimum 4.5 Vcc. Something's fishy. Did you have a multimeter? Measure voltage between GND (left bottom) and Vout (right bottom)

I just rewatched the video you submitted. I have the right voltage regulator U1, 662K. I have the older timing chip U2, NE555, but I'm supplying 5.0V so it should be good.

With the probe in water, Aout reads 0.82V With the probe dry, Aout reads 2.19V.

Sorry - voltage regulator U2, 662K

So that part is working! Now to find out why your Arduino doesn't catch up.

If you run the sketch above without the sensor connected, what values do you get?

Wire from sensor Aout at port A1 disconnected, i get values 153 to 162.

If you get the same values with the Aout connected / not connected, it means A1 is floating, ie no connection between sensor and A1. That's what you have to troubleshoot. Time to set your multimeter to continuity mode and get to work.

Wire from sensor Aout at port A1 reconnected, i get similar values, 153 to 162.