May 15, 2021 Arduino
Water level sensor bricks are designed for water level detection and can be widely used to detect rainfall, water level and even liquid leakage.
Connecting water level sensors to Arduino is a great way to detect leaks, spills, floods, rain, etc. I t can be used to detect the presence, water level, volume and lack of water. W hen this is used to remind you to water plants, there is a better Grove sensor. T he sensor has a series of exposed traces that read LOW when water is detected.
In this chapter, we will connect the water level sensor to the digital pin 8 on Arduino and will use a very convenient LED to help identify when the water level sensor is in contact with water sources.
You will need the following components:
Connect the components on the breadboard according to the circuit diagram, as shown in the following image.
Turn on the Arduino IDE software on your computer. U se arduino to encode and control your circuitry. /b11> Open a new sketch file by clicking New.
#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); } }
The water level sensor has three terminals: S, Vout (-) and GGND (-). Connect the sensor as follows:
When the sensor detects water, pin 8 on Arduino changes to LOW, and then the LED on Arduino lights up.
When the sensor detects water, you will see an indicator LED light on.