Soil moisture measurement sensor

    • The secondary directory
    • Two, wiring diagram
    • Complete code
    • 4. Experimental process and conclusion

The secondary directory

First, sensor introduction

  • Supply voltage: 3.3V or 5V
  • Output voltage: 0~ 2.3V
  • Operating current: Max. 20mA
  • Probe service life: about 1 year



  • Resistive soil moisture sensor is simple in structure and cheap in price. It can measure soil moisture through the contact between the nickel-plated circuit exposed on the circuit board and soil. The measured soil moisture is output by the sensor in the form of voltage signal. However, due to the uncertainty of the measured soil density and composition, the sensor is only suitable for the occasion where the accuracy requirement is not too high, and more hope to use the sensor to judge the general situation of soil moisture, through the sensor output voltage value to judge the degree of moisture content in the soil.
  • The soil moisture sensor probe is equivalent to a resistance, which is infinite when suspended, but in the soil, the greater the humidity, the smaller the resistance.
  • The DO pin of the sensor is used to indicate whether the moisture in the soil is higher or lower than a certain threshold value, and the corresponding threshold value is adjusted and controlled by the potentiometer. When the humidity is lower than the threshold value, DO outputs high level, and vice versa.
  • The AO pin of the sensor outputs an analog voltage signal to indicate the degree of soil moisture content.

Here, we only detect the voltage analog signal output by AO, because this voltage signal can reflect the specific water content in the soil. DO pins are easier to use and can be implemented using the GPIO library functions provided by Core if the developer is interested, but not covered here.

Two, wiring diagram

Complete code

Print () : LIB_UsbConfig() : LIB_UsbConfig() : LIB_UsbConfig("CDC") -- Configure the AD voltage collection function and set the maximum sampling value4096The corresponding3.6V Input voltage -- when the channel is full1When, the cache is full, and the collection interval of each point is300ms
LIB_ADConfig(1.300000)-- Start the big cyclewhile(GC(1) = =true)
do-- Every 300ms check whether A0 channel conversion is complete -- developers can also connect sensors to any channel a1-A3, or multiple channels to multiple sensors, the usage is the same as belowLIB_DelayMs(300)
    A0_full_flag, A0_buf = LIB_ADCheckBufFull("A0")
    if A0_full_flag == 1Then -- Print the AD sampling value of channel A0 and the corresponding voltage value print(string.format("A0=%04d Voltage=%.2fv",  A0_buf[1], A0_buf[1] *3.6/4096.0))
    end
end
Copy the code

4. Experimental process and conclusion

Step 1: Leave the sensor probe empty (do not touch the soil)





It can be seen that the sensor output voltage value in this state is 3.3V at full voltage

Step two: Dip the sensor probe into the water for observation





It can be seen that when the soil sensor probe is fully immersed in pure water, the voltage output by the sensor is about 1.18V

Step three: put the sensor probe into the soil with a certain humidity for observation





It can be seen that the output voltage of the sensor probe is 1.59V when it is put into the soil

Step 4: Add more water to the soil





After adding more water to the soil, you can see that the output voltage of the sensor is 1.31V

Conclusion:

As can be seen from the above experiment, the output voltage values of the sensor in the four states of “vacant” — >” immersed in pure water “– >” put into the soil” — >” add more water to the soil “are respectively 3.30V, 1.18V, 1.59V and 1.31V.

It can be concluded that when the proportion of moisture in the soil is higher, the voltage output by the sensor is lower.