目录

Arduino - Water Detector / Sensor

水传感器砖专为水质检测而设计,可广泛用于感应降雨,水位,甚至液体泄漏。

水检测器/传感器

将水传感器连接到Arduino是检测泄漏,溢出,洪水,雨水等的好方法。它可用于检测水的存在,水平,体积和/或缺水。 虽然这可以用来提醒你给植物浇水,但有一个更好的Grove传感器。 传感器有一系列暴露的痕迹,当检测到水时读数为低。

在本章中,我们将水传感器连接到Arduino上的数字引脚8,并将获得非常方便的LED,以帮助识别水传感器何时与水源接触。

组件的要求 (Components Required)

您将需要以下组件 -

  • 1 × Breadboard
  • 1×Arduino Uno R3
  • 1×水传感器
  • 1×led
  • 1×330欧姆电阻器

过程 (Procedure)

按照电路图并连接面包板上的组件,如下图所示。

水传感器电路连接

草图 (Sketch)

在您的计算机上打开Arduino IDE软件。 用Arduino语言编码将控制你的电路。 单击“新建”打开新的草图文件。

草图

Arduino代码 (Arduino Code)

#define Grove_Water_Sensor 8 // Attach Water sensor to Arduino Digital Pin 8
#define LED 9 // Attach an LED to Digital Pin 9 (or use onboard LED)
void setup() {
   pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
   pinMode(LED, OUTPUT); // The LED is an Output
}
void loop() {
   /* The water sensor will switch LOW when water is detected.
   Get the Arduino to illuminate the LED and activate the buzzer
   when water is detected, and switch both off when no water is present */
   if( digitalRead(Grove_Water_Sensor) == LOW) {
      digitalWrite(LED,HIGH);
   }else {
      digitalWrite(LED,LOW);
   }
}

Code to Note

水传感器有三个端子 - S,V 输出 (+)和GND( - )。 按如下方式连接传感器 -

  • 在Arduino板上将+ V s连接到+ 5v。
  • 将S连接到Arduino板上的数字引脚8。
  • 在Arduino上连接GND和GND。
  • 将LED连接到Arduino板上的数字引脚9。

当传感器检测到水时,Arduino上的引脚8变为低电平,然后Arduino上的LED变为ON。

结果 (Result)

当传感器检测到水时,您将看到指示LED亮起。

↑回到顶部↑
WIKI教程 @2018