How to make like the message send water level increase 50% then water level increase 70% then water level is in danger anyone know that help me please

#define trigPin1 A0
#define echoPin1 A1

long duration, distance;

char phone_no1[]="+60179487311";

char phone_no[]="+60120000015";

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print("FLOOD DETECTION CONTROL ROOM..");
for (int positionCounter = 0; positionCounter < 29; positionCounter++)
{
lcd.scrollDisplayLeft();
delay(500);
}

Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);

}

void loop()
{

digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration = pulseIn(echoPin1, HIGH);
distance = duration*0.034/2;

lcd.setCursor(0,0);

 lcd.print("WATER LEVEL:");
 lcd.print(distance);
 delay(500);
 lcd.clear();

static int flag;
if ( distance<=5)
{
if (! flag) SendMessage();
flag = 1;
}
else
{
flag = 0;
}

}

void SendMessage()
{
Serial.println("AT+CMGF=1");
delay(2000);
Serial.print("AT+CSCA="");
Serial.print(phone_no);
Serial.write(0x22);
Serial.write(0x0D);
Serial.write(0x0A);
delay(3000);
Serial.print("AT+CMGS="");
Serial.print(phone_no1);
Serial.write(0x22);
Serial.write(0x0D);
Serial.write(0x0A);
delay(3000);
Serial.print("water level is in danger level");
delay(500);
Serial.println(char(26));
}

Please edit your post to add code tags and explain where the problem lies.

See the "How to get the best out of this forum" post.

This one:

Something that might not be mentioned there - preferably use ctrl-T to autoformat your code prior to uploading. Your indentation is non-existent.

Maybe start with absolute values rather than percentage change - just check the level and send an appropriate message if a limit has been exceeded.

If you must use percentage increase, what's the timeframe and how do you reset the clock?

Your topic has been moved to a more suitable location on the. Installation and Troubleshooting is not for advice on (nor for problems with) your project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.