Water level sensor

    • First, sensor introduction
    • Two, wiring diagram
    • Complete code
    • 4. Experimental process and conclusion

First, sensor introduction



Water Sensor Sensor is simple in structure and cheap in price. It can measure the depth of liquid through the contact between the parallel lines exposed on the circuit board and the liquid. The depth value of the detected liquid level is output by the Sensor in the form of voltage signal. But because of the uncertainty of the purity of the water or other liquid and the impurities contained in it, the sensor is only suitable for the occasion where the precision requirement is not too high, and more hope to use the sensor to judge whether the water level rises and falls, as well as the approximate range of the rise and fall.

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: Put the sensor into an empty cup for observation





It can be seen that the voltage output by the sensor is 0V when there is no water

Step 2: Immerse half of the sensor in water for observation





It can be seen that the voltage output by the sensor is about 1.81V when the water level reaches the half-way state of sensor measurement

Step 3: Immerse all sensors in water for observation



It can be seen that the voltage output by the sensor is about 1.87V when the water level reaches the full measurement state of the sensor

Step 4: Take the sensor out of the water and observe



It can be seen that even after taking the sensor out of the water, there is still water on the surface of the sensor. At this time, the output voltage value is about 0.85V

Conclusion: It can be seen from the above experiments that the output voltage values of the sensor in the four states of “no water” — >” half process “– >” full process” — >” dehydration “are 0.00V, 1.81V, 1.88V, 0.85V respectively.

It can be seen that the water level depth and sensor output voltage can not be simply described by linear relationship. Therefore, in practical application, we need to carry out the actual measurement and calibration of the measured liquid to establish a mathematical relationship between the output voltage of the sensor and the actual liquid level. See shineblink.com for more details