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

将水传感器连接到Arduino是检测泄漏,溢出,洪水,雨水等的好方法。它可用于检测水的存在,水位,体积和/或不存在。 虽然这可以用来提醒你浇水你的植物,有一个更好的Grove传感器。 传感器具有暴露迹线的阵列,当检测到水时读取LOW。

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

必需的组件

您将需要以下组件 -

  • 1 × Breadboard 面包板

  • 1 × Arduino Uno R3

  • 1 × 水位传感器

  • 1 × led

  • 1 × 330欧姆电阻

程序

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

草图

在计算机上打开Arduino IDE软件。 在Arduino语言编码将控制你的电路。 通过单击新建打开一个新的草图文件。

Arduino代码

#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);
   }
}

代码说明

水位传感器具有三个端-S,V out(&正;)和GND( - )。 按如下所示连接传感器 -

  • 将Arduino板上的+ Vs连接到+ 5v。

  • 将S连接到Arduino板上的数字引脚号8。

  • 在Arduino上将GND连接到GND。

  • 将LED连接到Arduino板上的数字引脚编号9。

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

结果

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

新闻动态 联系方式 广告合作 招聘英才 安科实验室 帮助与反馈 About Us

Copyright © 2013 - 2019 Ancii.com All Rights Reserved京ICP备18063983号-5 京公网安备11010802014868号