Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Arduino water level detector/sensor


May 15, 2021 Arduino


Table of contents


Water level sensor bricks are designed for water level detection and can be widely used to detect rainfall, water level and even liquid leakage.

Arduino water level detector/sensor

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.

The required component

You will need the following components:

  • 1 × breadboard breadboard
  • 1 × Arduino Uno R3
  • 1 × water level sensor
  • 1 × led
  • 1 × 330 ohm resistor

Program

Connect the components on the breadboard according to the circuit diagram, as shown in the following image.

Arduino water level detector/sensor

Sketch

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.

Arduino water level detector/sensor

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 description

The water level sensor has three terminals: S, Vout (-) and GGND (-). Connect the sensor as follows:

  • Connect the plus vs to the plus 5v on the Arduino board.
  • Connect S to the digital pin 8 on the Arduino board.
  • Connect the GD to the GD on Arduino.
  • Connect the LED to the digital pin 9 on the Arduino board.

When the sensor detects water, pin 8 on Arduino changes to LOW, and then the LED on Arduino lights up.

Results

When the sensor detects water, you will see an indicator LED light on.