In this post I will show how to construct a circuit which will notify the user via SMS if the water supply to you area / home is initiated. It can show the time when the water is begin to supply and ended, average water flow speed in liter per minute and total water delivered to your tank in liters.
Introduction
We all know that life on earth is impossible without water, as human beings we use more water than any other species on earth consumes, not only for our survival but also to meet our luxury needs.
We not only consume water but also contaminate water bodies. The water consumption and demand is going to skyrocket in coming decades.
As a world citizen, it is our duty to save water, but as an individual we may not satisfy the entire world’s thirst by saving water but, we can definitely satisfy our family’s thirst as we might have healthy amount of water for brief period of time, even if no one around us saved water for future.
The supply of water in India and other rapidly developing countries is limited and also on high demand, moreover the water supply can begin without any official notification from the local government. This project will solve this issue for us.
Now let’s dive into the technical details of the project.
The Circuit:
The circuit consists of a water flow sensor YF-S201, an Arduino board which is the brain of the project, a GSM module (SIM 800 or SIM 900) for receiving SMS alerts on water supply and a real time clock module for tracking the correct time for water supply initiation and termination of water supply.
9 Volt supply is desirable for powering the Arduino board and the GSM module, it is recommended to provide the power supply from 9V adapters or homemade well-built, transformer based (LM 7809) supply.
The connection between Arduino and GSM module as follows:
Arduino TX to RX GSM module
Arduino RX to TX GSM module
Arduino GND to GND GSM module
Never try to power the GSM module from Arduino’s 5V output pin to 5V input of GSM module.
The RTC or real time clock module will track the time of arrival of water and termination of water supply.
That concludes the hardware.
To set the time on RTC we need to upload time setting program to RTC with the completed hardware setup. This will sync the time on your computer to RTC.
Download the RTC library file: github.com/PaulStoffregen/DS1307RTC
Program for setting time on RTC:
//-----------------------------------------------------------//
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
int P = A3; //Assign power pins for RTC
int N = A2;
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;
void setup() {
pinMode(P, OUTPUT);
pinMode(N, OUTPUT);
digitalWrite(P, HIGH);
digitalWrite(N, LOW);
bool parse = false;
bool config = false;
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(__TIME__);
Serial.print(", Date=");
Serial.println(__DATE__);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time=\"");
Serial.print(__TIME__);
Serial.print("\", Date=\"");
Serial.print(__DATE__);
Serial.println("\"");
}
}
void loop() {
}
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}
bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;
if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
//-----------------------------------------------------------//
· Upload the above code with completed hardware.
· Open the serial monitor and it shows time has been set.
· Now you are ready to move to next step.
You successfully set time to the RTC module.
Now, let’s upload the main program which will notify us via SMS.
Main Program:
//-----Program Developed by R.Girish-----//
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
int X;
int Y;
int sec = 50;
int t = 0;
int i = 0;
int check = 1;
int chk = 0;
int P = A3;
int N = A2;
int tim = 0;
float Time = 0;
float frequency = 0;
float waterFlow = 0;
float total = 0;
float LS = 0;
float average = 0;
const int input = A0;
const int test = 9;
void setup()
{
Serial.begin(9600);
pinMode(input, INPUT);
pinMode(test, OUTPUT);
analogWrite(test, 100);
pinMode(P, OUTPUT);
pinMode(N, OUTPUT);
digitalWrite(P, HIGH);
digitalWrite(N, LOW);
for (i = 0; i < sec; i++)
{
delay(1000);
}
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
Serial.println("AT+CMGF=1");
delay(500);
Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("Your water supply notification system is ready.");// The SMS text you want to send
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm))
{
if (tm.Hour > 12) //24Hrs to 12 Hrs conversion//
{
if (tm.Hour == 13) tim = 1;
if (tm.Hour == 14) tim = 2;
if (tm.Hour == 15) tim = 3;
if (tm.Hour == 16) tim = 4;
if (tm.Hour == 17) tim = 5;
if (tm.Hour == 18) tim = 6;
if (tm.Hour == 19) tim = 7;
if (tm.Hour == 20) tim = 8;
if (tm.Hour == 21) tim = 9;
if (tm.Hour == 22) tim = 10;
if (tm.Hour == 23) tim = 11;
}
else
{
tim = tm.Hour;
}
X = pulseIn(input, HIGH);
Y = pulseIn(input, LOW);
Time = X + Y;
frequency = 1000000 / Time;
waterFlow = frequency / 7.5;
LS = waterFlow / 60;
if (frequency >= 0)
{
if (isinf(frequency))
{
if (chk == 1)
{
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
Serial.println("AT+CMGF=1");
delay(500);
Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
Serial.print("Time: ");
delay(10);
Serial.print(tim);
delay(10);
Serial.print(":");
delay(10);
Serial.print(tm.Minute);
delay(10);
if (tm.Hour >= 12)
{
Serial.println(" PM");
}
if (tm.Hour < 12)
{
Serial.println(" AM");
}
delay(10);
Serial.println("Water Supply is Ended.");// The SMS text you want to send
delay(100);
Serial.print("Average Water Flow (Litre/Min): ");
delay(100);
Serial.println(average);
delay(100);
Serial.print("Total Water Delivered: ");
delay(100);
Serial.print(total);
delay(100);
Serial.println(" Litre");
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(5000);
t = 0;
total = 0;
average = 0;
chk = 0;
check = 1;
}
}
else
{
if (check == 1)
{
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
Serial.println("AT+CMGF=1");
delay(500);
Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
Serial.print("Time: ");
delay(10);
Serial.print(tim);
delay(10);
Serial.print(":");
delay(10);
Serial.print(tm.Minute);
delay(10);
if (tm.Hour >= 12)
{
Serial.println(" PM");
}
if (tm.Hour < 12)
{
Serial.println(" AM");
}
delay(10);
Serial.println("The water is being supplied now.");// The SMS text you want to send
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
check = 0;
chk = 1;
}
t = t + 1;
total = total + LS;
average = total / t;
average = average * 60;
}
}
delay(1000);
}
}
//-----Program Developed by R.Girish-----//
Note: You must upload the RTC time setting program to Arduino first and the main program second (with completed hardware setup), doing the opposite, the project will not work.
Here is the tested prototype’s SMS screen shot:
· After a minute powering the circuit ON, you will get an SMS saying that the system is ready.
· When the water starts flowing through the sensor, the system will notify the user with time.
· After the water supply is terminated the system will send another alert and summarize the session with time, average water flow and total water delivered to your tank.
Author’s prototype:
Please note that at the time of water arrival the water must free flow, meaning if there is any block or tap which is closed will not notify you.
If you have any questions regarding this project, feel free to express in the comment section, you may receive a quick reply.
Have Questions? Please Comment below to Solve your Queries! Comments must be Related to the above Topic!!