This tutorial will show you how to build and operate an alarm to detect water around a heater or other part of your home.
You use a water heater to produce the hot water from a spigot by switching the "hot" button of a sink on your house.
The majority of water heaters are huge hot water tanks, which will eventually fail and leak all of these tanks.
If you don't catch the leak early, you may have a big problem.
schematic diagramA water sensor measures the humidity level in the environment. A low water detector value means that the environment is highly humid. A high water detector value means that the environment is very dry. The sensor measures the voltage through both sides of the forklike part of the sensor. When the voltage is high, the resistance is high because between the trenches. There is no such substance as water. When the voltage is low, the resistance is low because there is a substance between the ties that conducts electricity (like water).
Arduino-----------soil moisture sensor Connection
5-V pin----------VCC
GND-------------GND
A0-------------A0
Arduino-----------piezo buzzer Connection
digital pin 9 ----------positive terminal
GND-------------Negative terminal
Arduino-----------piezo buzzer Connection
digital pin 7----------One terminal with register
GND-------------Another Terminal
programconst 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);
}
}
Download the Arduino program and start the Serial Monitor. The output of the Serial Monitor should be similar to:
As air is the substance in the sensor between the two sides, a high resistance measurement translates into a "very dry" reading. Soak a towel with water and wrap it around the water sensor fork.
You should see the reading going from damp to very wet depending on how difficult you push the wet towel down on the fork. The buzzer alarm should also be activated when the reading becomes damp. Now the alarm is tricked, and the buzzer continually generates a sound until the button is pressed to reset the alarm system.
program analysis const int VERY_WET = 400;
If the environment is wet, then the value from the water detector will be in the range of 401 to 500:
const int WET = 500;
If the environment is just damp, the value from the water detector will be in the range of 501 to 700:
const int DAMP = 700;
If the environment is dry, the value from the water detector will be in the range of 701 to 850:
const int DRY = 850;
If the environment is very dry, then the value from the water detector will be in the range of 851 to 950:
const int VERY_DRY = 950;
The piezo buzzer is assigned to digital pin 9 of the Arduino:
int BuzzerPin = 9;
The frequency of the sound the buzzer produces is set to 300:
int BuzzerFreq = 300;
The push-button is assigned to digital pin 7 of the Arduino:
int ButtonPin = 7;
The AlarmTripped variable is true if the water detector has sensed a damp environment and false otherwise. This variable is initialised to false:
boolean AlarmTripped = false;
The water detector is assigned to analogue pin 0 of the Arduino:
int DetectorPin = A0;
The RawValue variable holds the raw data that is read from the water detector and is initialised to 0:
int RawValue = 0;
void setup()
{
pinMode(DetectorPin, INPUT);
pinMode(ButtonPin, INPUT);
Serial.begin(9600);
Serial.println("Water Detector ...");
}
When the Arduino is activated or reset, the setup() function is named and does the following:
The pin on the Arduino connected to the analogue output pin of the water detector is set as an input pin so that the sensor reads the data.
The pin on the Arduino connected to the push button will be set as an input pin so you can read the voltages to see if the button is pushed.
It initialises the serial monitor, and thespeed of communication is set at 9, 600 baud. The Serial Monitor displays a text message indicating the start of the program.
void setup()
{
pinMode(DetectorPin, INPUT);
pinMode(ButtonPin, INPUT);
Serial.begin(9600);
Serial.println("Water Detector ...");
}
The PrintMoistureStatus() function prints out the moisture status of the water detector to the Serial Monitor, and the status is
1. VERY_WET,
2. WET,
3. DAMP,
4. DRY, or
5. VERY_DRY.
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");
}
}
Reads the push-button status and resets the alarm when the button is pressed.
Reads the water detector value. And Prints the soil moisture level in the Serial Monitor by calling the PrintMoistureStatus() function based on step 2.
Print the raw value read from the Serial Monitor water detector. The value read from the Stepp 2 water detector indicates a damp moisture level (700 or less). The function triggers an alarm.
The function produces a sound with the buzzer if the alarm has been tricked.If the alarm is not triggered, the function stops the buzzer sound.
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);
}
}
The loop() function is repeated until the Arduino is disconnected or reset, and it:
Reads the push-button status and resets the alarm when the button is pressed.
Reads the water detector value.
Prints the soil moisture level in the Serial Monitor by calling the PrintMoistureStatus() function based on step 2.
Print the raw value read from the Serial Monitor water detector.
If the value read from the water detector from step 2 indicates that the humidity level (700 or less) is waterproof, the function triggers the alarm.
The function produces a sound with the buzzer if the alarm has been tricked.
If the alarm is not tricked, the function stops any buzzer sound.
Comments