Products > SoilWatch 10

Soil Specific Calibration

<< < (4/4)

javierb:
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;
  }

pinolec:

--- Quote from: javierb 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;
  }

--- End quote ---

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: ---pinMode(7, OUTPUT);

--- End code ---

What sort of outputs are you getting?

Kind regards,
Piotr

javierb:
Hi Piotr!
Yes, i connect direct to the pin.
Why this is not recommended? Obviously before a set the pin as output.
Regards

javierb:
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

pinolec:

--- Quote from: javierb 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

--- End quote ---

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

Navigation

[0] Message Index

[*] Previous page

Go to full version