Arduino 简明教程
Arduino - Water Detector / Sensor
水传感器砖块专为检测水而设计,可广泛用于检测降雨、水位,甚至液体泄漏。
将水传感器连接到 Arduino 是检测泄漏、溢出、洪水、降雨等的绝佳方式。它可用于检测水是否存在、水位、水量和/或不存在。虽然这可用于提醒你给植物浇水,但有更好的 Grove 传感器可用于此目的。该传感器有一系列暴露的走线,在检测到水时读数为低。
在本章中,我们将水传感器连接到 Arduino 上的数字引脚 8,并将使用非常方便的 LED 来帮助识别水传感器何时与水源接触。
Components Required
您将需要以下组件:
-
1 × Breadboard
-
1 × Arduino Uno R3
-
1 × Water Sensor
-
1 × led
-
1 × 330 欧姆电阻
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);
}
}