Hi everybody
I'm new to this board and testing some things out with arduino.
I tried a code that prints me out the value of a moisture sensor, that works fine.
Now I wanted to add a second sensor to this installation on a different pin and used the code below, but now every time I serial print the values I get a zero on the second value.
Plant1 = 518
Plant2 = 0
1st question: What is my mistake in this consideration?
2nd question: Is there an easier way to accomplish such multiple sensor codes if I d'like to add some more sensors to it?
int val = 0;
int val2 = 0;
int soilPin = A0;
int soilPin2 = A2;
int soilPower = 7;
int soilPower2 = 6;
void setup()
{
Serial.begin(9600);
pinMode(soilPower, OUTPUT);
digitalWrite(soilPower,LOW);
pinMode(soilPower2, OUTPUT);
digitalWrite(soilPower2,LOW);
}
void loop()
{
Serial.print("Plant1 = ");
Serial.println(readSoil());
Serial.print("Plant2 = ");
Serial.println(readSoil2());
delay(1000);
}
int readSoil()
{
digitalWrite(soilPower, HIGH);
delay(100);
val = analogRead(soilPin);
digitalWrite(soilPower, LOW);
return val;
}
int readSoil2()
{
digitalWrite(soilPower2, HIGH);
delay(100);
val2 = analogRead(soilPin2);
digitalWrite(soilPower2, LOW);
return val2;
}