sarful
Created June 9, 2021 © Apache-2.0

How to build Arduino Water Detector Alarm

In this tutorial, you can learn How to build an Arduino Water Detector Alarm step by step complete process.

BeginnerFull instructions provided1 hour1
How to build Arduino Water Detector Alarm

Things used in this project

Hardware components

Arduino uno
×1
soil moisture sensor
×1
Piezo buzzer
×1
push button
×1
10-kΩ resistor
×1
breadboard
×1
connecting wire
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino Water Detector Alarm

Code

Arduino Water Detector Alarm

Arduino
const int VERY_WET = 400;
const int WET = 500;
const int DAMP = 700;
const int DRY = 850;
const int VERY_DRY = 950;
int BuzzerPin = 9;
int BuzzerFreq = 300;
int ButtonPin = 7;
boolean AlarmTripped = false;
int DetectorPin = A0;
int RawValue = 0;

void setup()
{
 pinMode(DetectorPin, INPUT);
 pinMode(ButtonPin, INPUT);
 Serial.begin(9600);
 Serial.println("Water Detector ...");
}

void PrintMoistureStatus(int value)
{
 Serial.print("MoistureStatus: ");
 if (value <= VERY_WET)
 {
    Serial.print("VERY_WET");
 }
 else
 if (value <= WET)
 {
    Serial.print("WET");
 }
 else
 if (value <= DAMP)
 {
    Serial.print("DAMP");
 }
 else
 if (value <= DRY)
 {
    Serial.print("DRY");
 }
 else
 {
    Serial.print("VERY_DRY");
 }
}


void loop()
{
 // Read Reset Button
 RawValue = digitalRead(ButtonPin);
 if (RawValue == 1)
 {
    AlarmTripped = false;
 }

 RawValue = analogRead(DetectorPin);
 PrintMoistureStatus(RawValue);
 Serial.print(" , RawValue: ");
 Serial.println(RawValue);

 // Check to see if Alarm should be 
 // tripped.
 if (RawValue <= DAMP)
 {
    AlarmTripped = true;
 }

 // Sound Alarm if alarm has been 
 // tripped.
 if (AlarmTripped)
 {
    tone(BuzzerPin, BuzzerFreq);
 }
 else
 {
    noTone(BuzzerPin);
 }
}

Credits

sarful

sarful

55 projects • 30 followers
I am Sarful , I am a Mechatronics Engineer & also a teacher I am Interested in the evolution of technology in the automation industry .

Comments