Arduino - Water Detector / Sensor

    0

    0

    Sohail Gulam

    unoarduino

    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.

    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.

    #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);
       }
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.