I´m having a lot of trouble with the calibration and Im not sure if the problem is the length of wire that Im using or the sensors themselves, the code, the method for calibration etc. The way I´m doing it is by getting the analog reading when the sensor is in dry soil and when it is in very wet soil, then I´m using the map function to scale those numbers from 0 to 100. Initially the calibrated values seem right, but suddenly the value that i end up getting when the sensor is in wet soil is accurate, but when it is in dry soil instead of 0 i get numbers like -30. This is the code that I´ve been using.
//Se conectan los sensores a los pines 36, 39, 34 y 35
int sensor1=36;
int sensor2=39;
int sensor3=34;
int sensor4=35;
void setup() {
Serial.begin(115200);
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
pinMode(sensor3,INPUT);
pinMode(sensor4,INPUT);
}
void loop() {
int humedad1=analogRead(sensor1);
int humedad2=analogRead(sensor2);
int humedad3=analogRead(sensor3);
int humedad4=analogRead(sensor4);
int porcentaje1=map(humedad1,2300, 1300, 0, 100);
int porcentaje2=map(humedad2,2000, 1230, 0, 100);
int porcentaje3=map(humedad3,1925, 1200, 0, 100);
int porcentaje4=map(humedad4,2045, 1320, 0, 100);
Serial.println(porcentaje1);
Serial.print("\t");
Serial.print(porcentaje2);
Serial.print("\t\t");
Serial.print(humedad3);
Serial.print("\t\t\t");
Serial.print(humedad4);
Serial.println();
delay(500);
}
Because of where I need to place the controller, an ESP32, the distance between the controller and the sensors would be about 12 meters (around 40ft ) and 6 meters (20ft) so thats the wire length that I´m using now and its an 18 AWG. I would really appreciate if someone could help me figure out whats going on. Thank you in advance
Long wires act as antennas, and usually lead to problems in several different forms. You may need shielding, etc.
For informed help, post a link to the exact sensor you are using, and a hand drawn wiring diagram.
Keep in mind that soil moisture is very difficult to measure electronically and no sensor is very accurate. The very cheap ones with two prongs are utterly worthless. At best you will have only a crude approximation to the truth.
A relatively accurate method of measuring "available" water content is to measure the weight loss upon baking the soil at high temperatures, until the weight stops changing. Some water is always retained.
I checked for the things they mention in that post and in the videos that the linked before buying the sensors to make sure they weren´t faulty so technically they should be fine but I´m still having problems
Calibrate each sensor individually, with nothing else connected, several times using different soil samples, so you get a feeling for the variations in behavior.
Only then consider connecting up the rest of that problematic circuitry, with household AC, motors and relays.
I see that dry soil gives A/D values of around 2000, so it's not bad if it's off by 30.
You can add a constrain() to the map function, so it doesn't get outside the 0-100 range.
Leo..
The problem is that everytime the moisture goes up and then down again those values change for some reason. It was 2000 but now its showing around 1800
I have a cup with dry soil, and another one with very wet soil. I dont have any reference device to calibrate the sensor. After I put the sensor in the wet soil, to return to what should be the dry value, I take the sensor out, I get it dry it with a tissue and then I put it back in the dry soil.
Its not always the same, sometimes the value that i was getting becomes higher and sometimes lower. That´s whats so frustrating. I do notice that the readings are different if the sensor is burried even a little bit deeper or if its more superficial, but still, even if i put the sensor back the same way it was the values keep changing too much.
What you're doing can't give accurate results, because soil doesn't compact the same against the sensor every time. Just calibrate 0-100 with a dry sensor (not in soil) and a wet sensor (in water).
Then learn at what percentage you should water your plants.
Be happy with three or four moisture stages. Dry/ok/wet.
Yep, a damaged silk screen could also change sensor readings.
Leo..
Ooh you´re right, I hadn´t really thought about the way the soil compacts. But I still have to make a scale from 0 to a 100 because I have to water the crops at a specific percentage for the proyect.