Arduino 简明教程
Arduino - Water Detector / Sensor
水传感器砖块专为检测水而设计,可广泛用于检测降雨、水位,甚至液体泄漏。
Water sensor brick is designed for water detection, which can be widely used in sensing rainfall, water level, and even liquid leakage.

将水传感器连接到 Arduino 是检测泄漏、溢出、洪水、降雨等的绝佳方式。它可用于检测水是否存在、水位、水量和/或不存在。虽然这可用于提醒你给植物浇水,但有更好的 Grove 传感器可用于此目的。该传感器有一系列暴露的走线,在检测到水时读数为低。
Connecting a water sensor to an Arduino is a great way to detect a leak, spill, flood, rain, etc. It can be used to detect the presence, the level, the volume and/or the absence of water. While this could be used to remind you to water your plants, there is a better Grove sensor for that. The sensor has an array of exposed traces, which read LOW when water is detected.
在本章中,我们将水传感器连接到 Arduino 上的数字引脚 8,并将使用非常方便的 LED 来帮助识别水传感器何时与水源接触。
In this chapter, we will connect the water sensor to Digital Pin 8 on Arduino, and will enlist the very handy LED to help identify when the water sensor comes into contact with a source of water.
Components Required
您将需要以下组件:
You will need the following components −
-
1 × Breadboard
-
1 × Arduino Uno R3
-
1 × Water Sensor
-
1 × led
-
1 × 330 ohm resistor
Procedure
按照电路图并将组件连接到面包板上,如下图所示。
Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below.

Sketch
在电脑上打开 Arduino IDE 软件。使用 Arduino 语言编写代码将控制你的电路。单击新建打开一个新草图文件。
Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking on New.

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、Vout(+) 和 GND (-)。如下连接传感器 −
Water sensor has three terminals - S, Vout(+), and GND (-). Connect the sensor as follows −
-
Connect the +Vs to +5v on your Arduino board.
-
Connect S to digital pin number 8 on Arduino board.
-
Connect GND with GND on Arduino.
-
Connect LED to digital pin number 9 in Arduino board.
当传感器检测到水时,Arduino 上的 8 号引脚变为 LOW,然后 Arduino 上的 LED 被点亮。
When the sensor detects water, pin 8 on Arduino becomes LOW and then the LED on Arduino is turned ON.