Author Topic: Soil Specific Calibration  (Read 100954 times)

javierb

  • Newbie
  • *
  • Posts: 6
Re: Soil Specific Calibration
« Reply #15 on: May 25, 2020, 04:55:51 AM »
Hi, can you help me with the sketch?
i am trying to obtain de VWC thought this function using milivolt as argument but i have very weird values, do you see something wrong with this part of the code?
I need to know 3 values of each lecture, raw, milivolts and VWC, and i call its separately and feed one with each other....

    int raw1 = raw_getValue(7, A1);
    float mVolt1 = mv_getValue(raw1);
    double vwc1 = vwc_getValue(mVolt1);

   
   int raw_getValue(uint8_t pinWrite, uint8_t pinRead) {
   int raw = 0;
   digitalWrite(pinWrite, HIGH);   // poner el Pin en HIGH
   delay(200);               // esperar...
   for (int i = 0; i < 3; i++) {
   raw += analogRead(pinRead);
   delay(200);  }
  digitalWrite(pinWrite, LOW);    // poner el Pin en LOW
  raw = raw/3;
  return raw;
  }

  float mv_getValue(int raw){
    float mV = (raw * (1.1/1023.0))*1000;
    return mV;
    }
 
  double vwc_getValue(float mv){
  float volt = mv/1000;
  double vwc = (5.5667*pow(volt, 3)) - (19.6738*pow(volt, 2)) + (31.0893*volt) - 6.7511;
  return vwc;
  }
« Last Edit: May 25, 2020, 04:58:09 AM by javierb »

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Soil Specific Calibration
« Reply #16 on: May 26, 2020, 07:14:24 AM »
Hi, can you help me with the sketch?
i am trying to obtain de VWC thought this function using milivolt as argument but i have very weird values, do you see something wrong with this part of the code?
I need to know 3 values of each lecture, raw, milivolts and VWC, and i call its separately and feed one with each other....

    int raw1 = raw_getValue(7, A1);
    float mVolt1 = mv_getValue(raw1);
    double vwc1 = vwc_getValue(mVolt1);

   
   int raw_getValue(uint8_t pinWrite, uint8_t pinRead) {
   int raw = 0;
   digitalWrite(pinWrite, HIGH);   // poner el Pin en HIGH
   delay(200);               // esperar...
   for (int i = 0; i < 3; i++) {
   raw += analogRead(pinRead);
   delay(200);  }
  digitalWrite(pinWrite, LOW);    // poner el Pin en LOW
  raw = raw/3;
  return raw;
  }

  float mv_getValue(int raw){
    float mV = (raw * (1.1/1023.0))*1000;
    return mV;
    }
 
  double vwc_getValue(float mv){
  float volt = mv/1000;
  double vwc = (5.5667*pow(volt, 3)) - (19.6738*pow(volt, 2)) + (31.0893*volt) - 6.7511;
  return vwc;
  }

Hi,

I can't see anything which may be wrong with the code at first glance. I do have some concerns.
Do you power the sensor straight from the pin? This will work for Arduino Uno but it is not recommended. To be able to power the sensor straight from the pin you need to set the pin as an output. Otherwise by default you just activating the pullup on this pin.
Code: [Select]
pinMode(7, OUTPUT);

What sort of outputs are you getting?

Kind regards,
Piotr

javierb

  • Newbie
  • *
  • Posts: 6
Re: Soil Specific Calibration
« Reply #17 on: June 09, 2020, 07:45:58 PM »
Hi Piotr!
Yes, i connect direct to the pin.
Why this is not recommended? Obviously before a set the pin as output.
Regards

javierb

  • Newbie
  • *
  • Posts: 6
Re: Soil Specific Calibration
« Reply #18 on: June 13, 2020, 04:05:19 AM »
Please Piotr, can you answer my questions?
I have 12 soilwatch 10 sensors (0-3v version)
This function is to obtain millivolts with the raw value from the pin analogRead.
   
    float mv_getValue(int raw){
    float mV = (raw * (1.1/1023.0))*1000;
    return mV;
    }

Perhaps this is my error, put 1,1 insted 3 or 3.3. The output of my sensors is 0 - 3 volts, and my board is arduino pro mini 3,3 v.
What number i must use 1.1, 3 or 3,3 ??

Regards
Javier
« Last Edit: June 13, 2020, 04:08:34 AM by javierb »

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Soil Specific Calibration
« Reply #19 on: June 13, 2020, 08:07:02 AM »
Hi Piotr!
Yes, i connect direct to the pin.
Why this is not recommended? Obviously before a set the pin as output.
Regards

Please see this post: https://pino-tech.eu/forum/soilwatch-10/sleep-mode-for-soil-watch-10/

For the other question, you should use the value for your calculations based on your voltage reference. Please read: https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

By default in many Arduino supported boards the reference voltage is the supply voltage.
If you power your Arduino pro mini with 3.3V then you should use 3.3 in your calculations. Make sure your supply voltage is stable as the results of your measurements depend on it.

Also do not power the sensor straight from the pin. With 3.3V there will be too big voltage drop to power the sensor.

Kind regards,
Piotr