# Calibration for capacitive soil moisture sensor

**URL:** <https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636>\
**Category:** General Guidance\
**Created:** [August 28, 2023, 1:51am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636 "2023-08-28T01:51:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 1:51am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/1 "2023-08-28T01:51:58Z")

</div>

Hello everyone. I´m creating an automated irrigation system with capacitive soil mositure sensors v2.0

 ![imagen](https://europe1.discourse-cdn.com/arduino/original/4X/e/d/1/ed15bf51b6b1dee874395e2c922f47883f19b9c2.jpeg)

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.

```arduino
//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 🙂

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 28, 2023, 1:57am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/2 "2023-08-28T01:57:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bluejets](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bluejets/32/1013044_2.png) [@bluejets](https://forum.arduino.cc/u/bluejets)\
**Post date:** [August 28, 2023, 2:10am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/3 "2023-08-28T02:10:12Z")

</div>

> [@Natalia1400](#):
>
> Hello everyone. I´m creating an automated irrigation system with capacitive soil mositure sensors v2.0

More details on everything............

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [August 28, 2023, 2:22am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/4 "2023-08-28T02:22:42Z")

</div>

[https://www.reddit.com/r/arduino/comments/q1anwt/beware\_of\_faulty\_capacitive\_soil\_moisture\_sensors/](https://www.reddit.com/r/arduino/comments/q1anwt/beware_of_faulty_capacitive_soil_moisture_sensors/)

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 3:24am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/5 "2023-08-28T03:24:30Z")

</div>

The wire is shielded with multiflex TFFN/PVC. This is the sensor Im using [https://www.amazon.es/Capacitive-Moisture-Corrosion-Resistant-Raspberry/dp/B07FLR13FS](https://www.amazon.es/Capacitive-Moisture-Corrosion-Resistant-Raspberry/dp/B07FLR13FS) but I didn´t buy it from this link, i bought it in a store that doesn´t have a webpage.

This is the diagram of my circuit, the grey wire is for 3,3V and the red one for 5V

 ![CircuitDiagram](https://europe1.discourse-cdn.com/arduino/original/4X/3/c/8/3c80287b545a1933a8f5e71ad7afe72499b0786c.jpeg)

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 3:27am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/6 "2023-08-28T03:27:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 28, 2023, 4:20am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/7 "2023-08-28T04:20:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [August 28, 2023, 4:24am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/8 "2023-08-28T04:24:03Z")

</div>

> [@Natalia1400](#):
>
> but when it is in dry soil instead of 0 i get numbers like -30

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..

```arduino
int porcentaje2 = map(humedad2, 2000, 1230, 0, 100);
porcenta2 = constrain(porcenta2, 0, 100);

```

---

<div class="post-metadata">

**Author:** ![paulpaulson](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulpaulson/32/363643_2.png) [@paulpaulson](https://forum.arduino.cc/u/paulpaulson)\
**Post date:** [August 28, 2023, 4:28am UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/9 "2023-08-28T04:28:25Z")

</div>

Hello [Natalia1400](https://forum.arduino.cc/u/Natalia1400)

Take a view here to gain the knowledge:

> **[ESP32 - Soil Moisture Sensor | ESP32 Tutorial](https://esp32io.com/tutorials/esp32-soil-moisture-sensor)**
>
> Learn how soil moisture sensor works, how to connect soil moisture sensor to ESP32, how to read moisture using ESP32. The detail instruction, code, wiring diagram, video tutorial, line-by-line code explanation are provided to help you quickly get...

hth

Have a nice day and enjoy coding in C++.

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 8:40pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/10 "2023-08-28T20:40:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 28, 2023, 8:47pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/11 "2023-08-28T20:47:13Z")

</div>

> [@Natalia1400](#):
>
> those values change for some reason.

That is how those sensors behave. They are neither accurate nor reliable, but are somewhat better than nothing.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [August 28, 2023, 9:21pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/12 "2023-08-28T21:21:05Z")

</div>

Hi, @Natalia1400

Can you please post some images of your calibration setup?

How are you measuring the moisture to calibrate the sensor?

How do you know after increasing the moisture, that you have returned to the previous level?

Thanks.. Tom... 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 9:31pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/13 "2023-08-28T21:31:57Z")

</div>

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.

 ![Setup](https://europe1.discourse-cdn.com/arduino/original/4X/5/4/2/542622fbc23e2dcbb3cc44c49fcb73cf457fdd6a.jpeg)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 28, 2023, 9:46pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/14 "2023-08-28T21:46:35Z")

</div>

> [@Natalia1400](#):
>
> I put it back in the dry soil.

What sort of variation do you see when you remove the sensor from the sample, and put in back in the same sample?

What happens when you pack the soil around the sensor?

Repeat a few times to get a feeling for the spread of values.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [August 28, 2023, 9:56pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/15 "2023-08-28T21:56:55Z")

</div>

Hi,  
Do you wipe the sensor dry before testing in each sample?

Do you insert the sensor to the same depth on the sensor when you try each sample?

I have some of those sensors and what annoys me is no conformal coating on the sensor circuit to isolate the circuit against humidity from the soil.

The circuit measures pF, so even breathing on the sensor circuit will possibly change the reading.

Tom.. 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 10:00pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/16 "2023-08-28T22:00:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 10:01pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/17 "2023-08-28T22:01:11Z")

</div>

yes, i wipe it and always put it back at the same depth

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 28, 2023, 10:17pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/18 "2023-08-28T22:17:31Z")

</div>

> [@Natalia1400](#):
>
> even if i put the sensor back the same way it was the values keep changing too much.

What you are doing is called "the scientific method", and is the best way to proceed.

If the sensor does not give repeatable measurements, it is simply not very useful. Hopefully, lesson learned.

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [August 28, 2023, 11:04pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/19 "2023-08-28T23:04:19Z")

</div>

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.

> [@TomGeorge](#):
>
> what annoys me is no conformal coating on the sensor...

Yep, a damaged silk screen could also change sensor readings.  
Leo..

---

<div class="post-metadata">

**Author:** ![Natalia1400](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@Natalia1400](https://forum.arduino.cc/u/Natalia1400)\
**Post date:** [August 28, 2023, 11:23pm UTC](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636/20 "2023-08-28T23:23:03Z")

</div>

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.

[Next page](https://forum.arduino.cc/t/calibration-for-capacitive-soil-moisture-sensor/1162636.md?page=2)
