#define FLOWRATE1     32
#define FLOWRATE2     33
#define PUMP          13
#define rled          19
#define yled          18
#define threshold     15
#define button        15
String number="0620572917";
#define sim           Serial2


float flowRate1,flowRate2;
long pretime=0;

void setup()
{
 Serial.begin(9600);
 delay(100);
 Serial2.begin(9600);
 pinMode(rled,OUTPUT);
 pinMode(yled,OUTPUT);
 pinMode(PUMP,OUTPUT);
 pinMode(button, INPUT_PULLUP);
 digitalWrite(yled,LOW);
 digitalWrite(rled,LOW);
 digitalWrite(PUMP,LOW);
}

void loop()
{
 get_data();
 long timeElapse=millis()-pretime;
 if((flowRate1-flowRate2)>threshold && timeElapse>10000)
 {
  digitalWrite(yled,LOW);
  digitalWrite(rled,HIGH);
  digitalWrite(PUMP,LOW);
  send_sms();
  pretime=millis();
 }
 if(digitalRead(button)==LOW)
 {
  delay(750);
  digitalWrite(rled,LOW);
  digitalWrite(yled,HIGH);
  digitalWrite(PUMP,HIGH);
 }
}

void get_data() 
{
  flowRate1=map(analogRead(FLOWRATE1),0,4095,0,100);
  Serial.print("flowrate1:");
  Serial.println(flowRate1);
  flowRate2=map(analogRead(FLOWRATE2),0,4095,0,100);
  Serial.print("flowrate2:");
  Serial.println(flowRate2);
}

void send_sms() 
{     
  sim.println("AT+CMGF=1\r");
  delay(100);
  sim.println("AT+CMGS=\"" + number + "\"\r");
  delay(500);
  sim.println("WATER LEAKAGE DETECTED");
  delay(500);
  sim.println((char)26);
  delay(500);
  Serial.println("SMS SENT SUCCESSFULLY");
}
PIPE LINE WATER LEAKAGE DETECTION SYSTEM
FLOWRATE SENSOR 1
FLOWRATE SENSOR 2
gsm-modemBreakout
NOCOMNCVCCGNDINLED1PWRRelay Module