Trouble with YL69

Hi everyone, i¨m using a YL69 to read the moisture of the soil, the thing is that i would like to have these values in percentage, i think it is more speaking that the measures that it actually gives being 1023 DRY and 0 WET.

Does anyone have a code or function or any advice of how could i make it??

I had read that i could use this:

float percentage = (float)((sensorValue - min) * 100) / (max - min)

And or this:

sensorValue = map(sensorValue, 0, 1023, min, max);

But i¨m not sure how...anyone please?!

Use both equations, compare and see what it looks like!

Hi! yes that is what i had done, so this is my code:

const int SoilMoisturePin=A0;

int min= 266;
int max= 1021;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  //int sensorValue = map(sensorValue, 0, 1023, min, max);
  int sensorValue = analogRead(SoilMoisturePin);
  float percentage = (float)((sensorValue - min) * 100) / (max - min);
  Serial.print("\nHum Tierr:");
  Serial.print(percentage);
  Serial.print(" %");
  delay(1500);
}

and here the picture of the output...

Where i have 13.20% the sensor was completly dry and for -1.32%, i put it inside water...any idea what is going on?

Every sensor needs to be calibrated. Perform a calibration.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.