SOURCE CODE
#define trigPin1 A0
#define echoPin1 A1
long duration, distance;
char phone_no1[]="+60179487311";
char phone_no[]="+60181000108";
#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();
if( distance<=5)
{
SendMessage();
}
}
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));
}
gcjr
2
set a flag after send the message and reset the flag when distance > 5
static int flag;
if( distance<=5) {
SendMessage();
flag = 1
}
else {
flag = 0;
}
b707
3
You forget to test the flag....
1 Like
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
gcjr
8
need to change thresholds and MaxDist
#define trigPin1 A0
#define echoPin1 A1
# include <LiquidCrystal.h>
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
long duration;
const int MaxDist = 100;
int distance = MaxDist;
int thresh [] = { 5, 10, 30 };
const int Nthresh = sizeof(thresh) / sizeof(int);
int thrIdx = Nthresh;
int thrIdxLst = Nthresh+1;
char phone_no1 [] = "+60179487311";
char phone_no [] = "+60181000108";
char s [80];
// -----------------------------------------------------------------------------
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);
digitalWrite (trigPin1, LOW);
}
// -----------------------------------------------------------------------------
void loop ()
{
digitalWrite (trigPin1, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin1, LOW);
delayMicroseconds (2);
duration = pulseIn (echoPin1, HIGH);
distance = duration*0.034/2;
lcd.clear ();
lcd.setCursor (0,0);
lcd.print ("WATER LEVEL:");
lcd.print (distance);
for (int i = 0; i < Nthresh; i++) {
thrIdx = Nthresh+1;
if (distance <= thresh [i]) {
thrIdx = i;
break;
}
}
if (thrIdxLst != thrIdx)
SendMessage (thrIdx);
thrIdxLst = thrIdx;
delay (500);
}
void SendMessage (
int idx )
{
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);
sprintf (s, "water level < %d%%", 100 * thresh [idx] / MaxDist);
Serial.print (s);
delay (500);
Serial.println (char (26));
}
thanksss but can u help me when the water level reach < 5% i want the message send like water level is in danger
how to do like that
system
Closed
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.