Soil Moisture Sensor V1.2

I got the Soil Moisture Sensor V1.2 a couple of weeks ago and finally decided to do some project with it.

The code I used is reading 0 when in water or in wet soil. However, when I try to short it with a finger, the value jumps up to around 25. I would be glad for any kind of help,

Thank you in advance.

Code:

int moisture = A4;

void setup() {

Serial.begin(9600);
pinMode(moisture,INPUT);

}

void loop() {

Serial.println(analogRead(moisture));
delay(100);

}

It would help if you told us what sensor you purchased, a link to the technical information is needed. google found 577,000 sensors.

It is in the title "Soil Moisture Sensor V1.2"

The op will want to start off with a lesson on reading the A:D converter.

Then the OP will want to put the moisture sensor in dry air and note this reading.0% moisture content

Next, the OP will want to put the sensor in water, and note this reading. 100% moisture content.

The OP may want to look at the sensor and say, "Oi! There is exposed electronics on the board."

I used a hot glue gun on low heat to seal up the electronics.

Here is my code to read the sensor and convert the reading to a %

void fReadAD( void * parameter )
{
  float    ADbits = 4096.0f;
  float    uPvolts = 3.3f;
  float    adcValue_b = 0.0f; //plant in yellow pot
  uint64_t TimePastKalman  = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
  float    WetValue = 1.07f; // value found by putting sensor in water
  float    DryValue = 2.732f; // value of probe when held in air
  float    Range = DryValue - WetValue;
  float    RemainingMoisture = 100.0f;
  SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
  for (;;)
  {
    xEventGroupWaitBits (eg, evtADCreading, pdTRUE, pdTRUE, portMAX_DELAY ); //
    adcValue_b = float( adc1_get_raw(ADC1_CHANNEL_3) ); //take a raw ADC reading
    adcValue_b = ( adcValue_b * uPvolts ) / ADbits; //calculate voltage
    KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
    adcValue_b = KF_ADC_b.updateEstimate( adcValue_b ); // apply simple Kalman filter
    TimePastKalman = esp_timer_get_time(); // time of update complete
    RemainingMoisture = 100.0f * (1 - ((adcValue_b - WetValue) / (DryValue - WetValue))); //remaining moisture =  1-(xTarget - xMin) / (xMax - xMin) as a percentage of the sensor wet dry volatges
    xQueueOverwrite( xQ_RM, (void *) &RemainingMoisture );
    //log_i( "adcValue_b = %f remaining moisture %f%", adcValue_b, RemainingMoisture );
  }
  vTaskDelete( NULL );
}

The code is for an ESP32. The OP will want to make adjustments to the code depending upon the MCU used.

1 Like

It is reading 0 at all times

Great attitude - you should go far.
Please.

Then you'll want to review how to use the Analog inputs. You'll want to properly power and ground the sensor. Have you considered posting a picture of your wiring? A Schematic.

3 pins
GND - GND
VCC - 5V
AOUT - A4

Same as the sensor I am using, except for A:D pin assignment.

This one?

You can use pulseIn() to get the current measurement.

Seems this version of the sensor does a pulse analog conversion, so it should be read with ananlogRead.

Has the OP tried using A3 instead of A4? A4 doubles as one of the I2C lines.

fixed

How?

There are hardware issues with these sensors, which are easy to fix.
Leo..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.