简介

这是DFRobot新推出的一款防水式土壤湿度传感器,与老款的土壤湿度传感器相比,增加了防水性能,优化了防腐蚀性能,增加了极板长度并优化了电路性能。 电容式的土壤湿度传感器,相比电阻式传感器,解决了电阻式传感器易被腐蚀的问题,能够长时间插入泥土不被腐蚀。该款传感器增加了防水性能,传感器全部浸泡在水中仍能正常使用;增长了电容极板的长度,可以更精确的测量土壤湿度信息。该款传感器具有较宽的输入电压,能够在3.3V-5.5V宽电压下工作。兼容Arduino、ESP32、micro:bit、掌控板、树莓派等常见控制板。标准设计的DFRobot-Gravity接口可以直接与Gavity IO扩展板相连接。而树莓派之类的微型PC,则需要外接一个ADC(模拟信号转数字信号)模块就可以工作。

特性

参数规格

SEN0308外形尺寸图

使用教程

准备

接线图

颜色 接口
红色线 VCC
黑色线 GND
黄色线 A0
屏蔽线 GND

SEN0308连线图.jpg

测试代码

在使用传感器前,我们需要获取传感器的测量范围。代码如下:

    void setup() {
      Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
    }
    void loop() {
      Serial.println(analogRead(A0)); //connect sensor and print the value to serial
      delay(100);
    }

图形化代码

校准步骤

干湿度校准

校准说明:通过分别读取传感器在空气中和水中的数值来限定一个测量范围 校准步骤

SEN0308串口监视器波特率设置.png

SEN0308串口监视器水中和空气中的数值.jpg

区间设定

由于传感器数值会受到入土深度、土壤松紧度的影响,只能检测到土壤的相对湿度,我们把湿度的范围分为三等分,分别表示干燥、湿润、非常潮湿。之前记入的两个数据为湿度区间。例如:空气中读数为570,水中读数为0,这样就可以分为(570,380],(380,190],(190,0]这三个区间分别代表干燥、湿润、非常潮湿。

样例代码

把刚刚记录的两组数据带入到下面的测试代码中。 空气中的数值带入到样例代码第17行

    const int AirValue = ;     //you need to change this value that you had recorded in the air

水中的数值带入到样例代码第18行

    const int WaterValue = ;     //you need to change this value that you had recorded in the water

样例代码如下:

    /***************************************************
     This example reads Analog Waterproof Capacitive Soil Moisture Sensor.

     Created 2019-10-25
     By Felix Fu <Felix.Fu@dfrobot.com>

     GNU Lesser General Public License.
     See <https://www.gnu.org/licenses/> for details.
     All above must be included in any redistribution
     ****************************************************/

    /***********Notice and Trouble shooting***************
     1.Connection and Diagram can be found here
     2.This code is tested on Arduino Uno.
     ****************************************************/

    const int AirValue = 570;   //you need to change this value that you had recorded in the air
    const int WaterValue = 0;  //you need to change this value that you had recorded in the water

    int intervals = (AirValue - WaterValue)/3;
    int soilMoistureValue = 0;
    void setup() {
      Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
    }
    void loop() {
    soilMoistureValue = analogRead(A0);  //put Sensor insert into soil
    if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
    {
      Serial.println("Very Wet");
    }
    else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
    {
      Serial.println("Wet");
    }
    else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
    {
      Serial.println("Dry");
    }
    delay(100);
    }

疑难解答

Q 1. 为什么我使用Romeo主控时,传感器的读数和实际值差异很大?
A: 由于Romeo的模拟口A0口上外接有按钮,所以请将按钮旁边的开关拨到 Off 的位置,或者使用其他模拟口。
Q 2. 为什么我使用ESP32或者行空板等主控时,传感器的读数变得特别大?
A: 样例中使用的是Arduino UNO主控板,工作电压是5V,且UNO上的ADC是10位的,读取数值区间在0-1023。而ESP32主控的供电电压为3.3V,其ADC为12位,读取数值区间是0-4095。所以使用ESP32主控时,传感器的读数变大了。

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖!

更多

SEN0308 原理图

更多问题及有趣的应用,请访问论坛(链接

DFshopping_car1.png DFRobot商城购买链接