Hi all,
Can someone that knows more about analogue pins than me please help.
Now, right from the get go I know this is my lack of knowledge so I hope you can help
This is on a Mega 2560 board - Note - I haven't done any analogue configuration in the Set Up function. I have tried this on pins A3 to A1 but no difference in outcome
I'm using 3 DFRobot waterproof capacitive soil moisture sensors.
When the sensor is completely immersed in water I can read 0.39Vdc on a multiple meter
When the sensor is in dry air I can read 2.28Vdc on a multiple meter
I have the following function that is producing some very strange results that I can not for the life of me understand why.
void Read_Soil_Moisture() {
double Range = 0;
double Sensor_Value_01 = 0;
double Sensor_Value_02 = 0;
double Sensor_Value_03 = 0;
double Sensor_Min = 0.29; // 0.29Vdc - Completely wet (measured via muiltple meter)
double Sensor_Max = 2.28; // 2.28Vdc - Completely dry (measured via muiltple meter)
Range = Sensor_Max - Sensor_Min; // range is Vdc from completely wet to completely dry
Sensor_Value_01 = analogRead(Soil_Moisture_01_Pin); // read analogue A7
Soil_Moisture_Percent_01 = 100 - ((Sensor_Value_01 / Range) * 100); // calculate the inverse percentage reading
Sensor_Value_02 = analogRead(Soil_Moisture_02_Pin); // read analogue A5
Soil_Moisture_Percent_02 = 100 - ((Sensor_Value_02 / Range) * 100); // calculate the inverse percentage reading
Sensor_Value_03 = analogRead(Soil_Moisture_03_Pin); // read analogue A6
Soil_Moisture_Percent_03 = 100 - ((Sensor_Value_03 / Range) * 100); // calculate the inverse percentage reading
Serial.print("Range ");
Serial.print(Range, 2);
Serial.print(" Vdc ");
Serial.print("A7 ");
Serial.print(Sensor_Value_01, 2);
Serial.print(" Vdc ");
Serial.print(" A6 ");
Serial.print(Sensor_Value_02, 2);
Serial.print(" Vdc ");
Serial.print(" A5 ");
Serial.print(Sensor_Value_03, 2);
Serial.println(" Vdc ");
}
Note - I have kept local variables purely to make reading the function easier
The Serial Mointer output (examples) are
Range 1.99 Vdc A7 0.00 Vdc A6 461.00 Vdc A5 451.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 459.00 Vdc A5 449.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 462.00 Vdc A5 452.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 460.00 Vdc A5 450.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 462.00 Vdc A5 451.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 459.00 Vdc A5 449.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 461.00 Vdc A5 451.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 459.00 Vdc A5 450.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 462.00 Vdc A5 452.00 Vdc
Range 1.99 Vdc A7 0.00 Vdc A6 459.00 Vdc A5 449.00 Vdc
So the range is correct but not only are the A7, A6 & A5 readings completely wrong they are erratic and all over the place which means I get a very unstable display when in fact the real life values barely change - as one would expect when measuring soil moisture
Question - how do I make the readings more stable - can I use pull up or pull down resistors etc
Where does the 461Vdc type readings come from - if I had 461Vdc on an analogue pin Id have smoke
Anyway, could some one with much grater knowledge than me please help out
As always your help will be very much appreciated
Kind Regards Grant Brown