Multiple capacitive soil moisture sensors trouble

Hi,
I am using capacitive soil moisture sensors with the ratings as shown in the attachment in order to monitor my soil water levels.

When I hook up sensors identically to the attached circuit, the first three sensors give out correct readings, however the fourth sensor starts giving out random values. I would like to know if anyone has worked with a similar setup and experienced a similar problem and maybe a way around it.

I used the following code. I have tried doing multiple analogRead() values and giving a delay in order to allow the ADC of the arduino uno to comply, but this has not solved the issue.

void setup(){
  // put your setup code here, to run once:
 Serial.begin(9600);  //com enable
 int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
   int sensorValue3 = analogRead(A4);
    int sensorValue4 = analogRead(A5); //assigning analog pins
 int moist1;
 int moist2;
 int moist3;
 int moist4; //variables for calculations
 }

void loop(){
int moist1 = analogRead(A1);
   delay(10);  
   moist1 = analogRead(A1); //take reading 1
   Serial.print("sensor 1's reading: ");
   Serial.println(moist1);
   delay(500); //delay to allow ADC
   
   int moist2 = analogRead(A2);
   delay(10);
   moist2 = analogRead(A2);  //take reading 2
   Serial.print("sensor 2's reading: ");
   Serial.println(moist2);
   delay(500);
   
   int moist3 = analogRead(A4);
   delay(10);
   moist3 = analogRead(A4);  //take reading 3
   Serial.print("sensor 3's reading: ");
   Serial.println(moist3);
   delay(500);
   
   int moist4 = analogRead(A5);
   delay(10);
   moist1 = analogRead(A1); //take reading 4
   Serial.print("sensor 4's reading: ");
   Serial.println(moist4);
   delay(500);
}

sms.png

moist1 = analogRead(A1); //take reading 4

OP, do look up arrays. Makes reading four sensors in a row much easier and your code shorter.

Wawa:
moist1 = analogRead(A1); //take reading 4

I have fixed the coding error, however the problem persists where three analog signals are read correctly and one analog sensor giving out random values from 0 to 1023.

I am thinking that due to too many analog inputs being wired from the arduino itself, I am getting high noise levels.
Should I try powering the sensors externally or perhaps interfacing a capacitor in the circuit to filter out some noise?

Random values on an analog pin indicate a floating pin, i.e. no connection.

  1. make sure the pins your sensors are connected to actually match the pins you try to read in software.
  2. make sure there is actually a connection between the pin and the sensor - use your multimeter to double check wiring if in doubt. If you use a solderless breadboard poor electrical connections are expected.

Lifesaver !!! I changed breadboard to a soldered one and readings are now perfect.

wvmarle:
Random values on an analog pin indicate a floating pin, i.e. no connection.

  1. make sure the pins your sensors are connected to actually match the pins you try to read in software.
  2. make sure there is actually a connection between the pin and the sensor - use your multimeter to double check wiring if in doubt. If you use a solderless breadboard poor electrical connections are expected.