Njegomir Skola
Published © CC BY

Water Detection

If it detects water, the circuit gives an audible alarm.

BeginnerWork in progress30 minutes3,411
Water Detection

Things used in this project

Story

Read more

Schematics

connecting

It is used Soil Hygrometer Humidity Detection Module Moisture Sensor For Arduino

Code

Water detector

C Header File
int digitaInput = 6;
int speaker =5;
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(digitaInput, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(speaker, OUTPUT);
  
}

// the loop routine runs over and over again forever:
void loop() {
  
  while(digitalRead(digitaInput)==HIGH)
   {
    digitalWrite(LED_BUILTIN, HIGH);
     
    Serial.println("Dry");
   }
   while(digitalRead(digitaInput)==LOW)
   {
    digitalWrite(LED_BUILTIN, LOW);
     digitalWrite(speaker, HIGH); 
     delay(1);
     digitalWrite(speaker, LOW); 
     delay(1);
    Serial.println("Wet");
    }
   
  delay(1000);
}

Credits

Njegomir Skola

Njegomir Skola

1 project • 2 followers
Teacher in secondary school.

Comments