Would like help in figuring out this formula, not something I wrote ,its all over the web in some form, percent = 2.718282 * 2.718282 * (.008985 * moistVal + 0.207762); When I put probes in room temperature water(galvanized nails) I read 69% ,if I remove probes from water and jump a wire to the 5v connection I get about the same reading. If I soak the sponge , no matter how wet it is I get the same value. Remove the probes I get 1% which is negligible . When the sponge is absorbing water it does climb as expected , just trying to first off , understand the math and secondly find a way to calibrate this. I would assume that I should get closer to around 95% not really expecting 100% moisture, with a reading of 1023 makes me believe that this is voltage .Think it could be a point slope formula but not sure by the math and the readings. Thanks
int moistPin = 0;
int moistVal = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
moistVal = analogRead(moistPin);
Serial.println(moistVal);
int percent = 2.718282 * 2.718282 * (.008985 * moistVal + 0.207762); //calculate percent for probes about 1 - 1.5 inches apart (+ 0.207762)
Serial.print(percent);
Serial.println("% Moisture ");
if(percent<30)
{digitalWrite(4,HIGH);}// if the sensor value is below 50% led on your nano will glow else it is off
else
{digitalWrite(4,LOW);}
delay(250); // for stability
}
Larry, remember your chemistry! Galvanized nails are steel(iron) coated with zinc. that makes a wonderful battery. Use two pieces of copper wire unless you have access to platinum wire.
So I tried the copper wires as suggested , with wires in water moisture readings were showing a value of 49% and
a reading of 712 . Inserted the nails for comparison with at least 1" of water covering nails and read 61% and a reading of 899. That's why I was asking for the help on the math that was used. I don't quite understand the calculation.
Soil moisture with an electrolysis based device is dependant on soil composition
Distance of electrodes
And as electrolysis occurs resistance will change.
Resistance will change but i would expect a relatively small window on the ADC.
Also over time i would expect there to be a range shift as the metals in the sensor change
Try an experiment
Get totally dry soil. Oven baked dry.
Put in your sensor.
Record reading.
Fill with water till submerged
Record reading.
Allow to drain.
Take readings daily untill you have the soil so dry that it is hard.
Record readings.
If you touch the soil Daily you can note your perception of dryness as well.
That would be a means of calibration to conditions
Trying to measure the percentage of moisture , reason for water test would be that when submerged in water , that would be the highest test result .I would like to know that when it reads 40% , that the moisture content of the soil is actually close to that .
Trying to build a plant watering system ,I know that their are several out there but why would I want to just copy someone else work , I wouldn't learn anything there and if I wanted to change something I probably would not know how. The formula given is one I got from the web and have seen that used a few times before, I just don't understand how it is derived or worked.(percent = 2.718282 * 2.718282 * (.008985 * moistVal + 0.207762). What does the numbers represent and how is it calculated?
Dave in nj I understand what you are saying here but at this point in time I would like to know that the calculations actually work then as you suggest sample the soil to get a min/max before adding moisture so you know it is correct. My goal would to be to keep soil between 30 to 40% or in that range.
if the soil is sand, clay or loam, the calculations would be different.
if the pins were 50mm or 6 CM apart, the calculations would be different.
if the soil and water resistance were different, acidic, neutral, etc...
the calculations would be different.
what does 2.718282 represent ?
0.008985 ?
0.207762 ?
if you are passing 5 volts between pins and the resistance between pins is 6,000 ohms,
you will get a value based on a 10k voltage divider that is different than an 8k voltage divider.
As the moisture changes, and the resistance changes, what does that calculation represent ?
Larryfos:
Dave in nj I understand what you are saying here but at this point in time I would like to know that the calculations actually work then as you suggest sample the soil to get a min/max before adding moisture so you know it is correct. My goal would to be to keep soil between 30 to 40% or in that range.
Prepare a soil sample with 30% humidity. Stick your probes in, take reading. Don't bother with calculations, just take the raw analog reading.
Then prepare a soil sample with 40% humidity. Stick your probes in, take reading. Again, just the analog reading.
Repeat with 20%, 50%, 60% for good measure. If you're lucky (really lucky) the values are in order of moisture level. They will probably be kinda more or less somewhat in order of moisture level, and when plotted vaguely represent a relationship between the two. Could be linear, probably not. When you stick the probes in the soil you really want to measure you're likely off again.
Long story short: this is not a reliable method to measure soil moisture, definitely not at that precision. Corrosion, electrolyses, type and quantity of ions in the soil (from a.o. fertilisers), migration of ions those in the soil as the current flows, that are just a some of the reasons it is not reliable.
By the way, while copper is an important trace nutrient, the quantities given off by one of the copper wires (the positive one, where the copper is electrolysed) are quite certainly unhealthy for your plants.
I did prepare some galvanized nails soldered copper 24ga wires to them, so I would be using thoes if I can get things the way I want them. I realize different soil mixtures will react differently but for now I was just trying to get some understanding as to how the math worked and how I could apply it to my project.
I did realize the I was more that likely reading a voltage across the probes but was lost on the math calculations, didn't really care what they read, just wanted to manipulate them to read what I expected, if that makes any sense.
As far as starting with dry product(soil) and adding the percentage of moisture and measuring it , not sure how I would do that unless I used possibly a tensiometer.I guess I could start with dry soil and add water , subtract the weight when dry compare to wet then divide . So all good suggestions here, Thanks all I will just beat the hell out of these suggestions and maybe learn something.
I would get a capacitative soil sensor and focus on getting all else done. Here in Europe they are about $3. Pretty easy to work with. Beyond the accuracy issue the probe as you plan to use will suffer from corrosion sooner or later.
If you happen to run the sensor on battery power you can power it from a digital pin and switch that on only when needed. The Arduino Pro mini I use mostly sleeps. It reads the sensor every 3 hours which is plenty for soil moisture and sends the data to a wall powered hub with a nRf24L01.
Larryfos, I'm afraid that you have been fooled.
Those numbers "2.718282" and ".008985" and "0.207762" are totally nonsense.
Sticking two metals in soil and have one metal continuous 5V on it, that's just rubbish.
In some situations, with a certain type of soil or water, with a certain temperature, with certain metals, for a single measurement of the humidity, then it might work for one minute (just kidding, it will totally fail).
Sorry for my blunt post, I felt that someone had to say it how it is.
To measure the soil humidity, use a capacitive sensor as Aggertroll wrote.
Don't try to find a better resistance tester, use a capacitive sensor.
The only problem that you have to solve is if it is "capacitive" or "capacitative" :o
You have to look at the maths too - you are using integers as input then multiplying with numbers that have several decimal places which will have little or no effect of your result .
2.718282 is meaningless as a multiplier if your answer only has a resolution of one part in 1024.
This may not be much help, but clearly 2.7218... is the value of Euler's number, e, so part of the formula is really (e^2)(.008985*moistVal +0.207762), which is very strange. Is the formula written correctly?. I could image maybe needing to use a log function to fit a very wide range of values, but simply multiplying by the value of e is weird.
Found the original project. http://create.arduino.cc/projecthub/millerman4487/diy-plant-moisture-sensor-474543 Even the original author could not remember how he derived/found the formula. One responder also noted that the 2.7218.. was Euler's number as well, It did not make sense to him either; it simply is an unnecessary multiplier.
The best course is not to even trust that formula and come up with your own, based on you own specific soil and the amount of water added. For instance, http://soil-water-compendium/soil-moisture-sensor-calibration/ describes in detail how to do this. Even that process will not be perfect, because soil as undisturbed compared to in a pot will have different compaction and therefore different electrical characteristics. Ultimately, you will end up calibrating against whether the plants leaves start drooping or worse.
Meanwhile... Aggertroll and me are waiting until we can say: "Told you so".
See reply #11 and #12.
Sticking two metals in soil is to play with electronics and Arduino and see what is happening and learn from that. It can not be used in a real project ! It will fail after a minute or after a month. Therefor it is totally worthless.
Larryfos does actually want to know the soil humidity for a real project.
Please stop fooling around everyone. Don't try to fix a bogus calculation. Don't try to make something work that will never seriously work.
now : .008985* moistVal = 0.008985 * 1023 = 9.191655
so, you are going to take an integer at max of 1023, turn it into a float
then add a correction of 0.207762
then multiply by e^2
I think we all knew this was just bogus from the beginning.
the only bit that would really have any effect is the correction.
turn 1023 into 9.191655 and add 0.207762 ( about 2 % of reading)
turn 102 into 0.91647 and add 0.207762 (about 25% of reading )
This is the only part that would actually do anything with the value.
you could substitute Pi, or your mothers birthday for the front bits. then scale it to whatever you want.
It just proves that 96% of people believe you when you use statistics and decimal places
and the other 2/3 are not really sure.