Hello, this is a water level indicator. I have found the code in the internet, modified it to suit my needs. but the problem now is that the serial print/SMS is looping on the current status. How do I make the system only send a single message when it detects a water change or the switch turns on. The LED works well. Ps. I change mySerial to Serial for simulation.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7,8);
byte sensorPin[] = {11, 12, 13};
byte ledPin[] = {8, 9, 10}; // number of leds = numbers of sensors
const byte sensors = 3;
int level = 0;
char phonenum[] = "0";
int a=0;
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
for(int i = 0; i < sensors; i++)
{
pinMode(sensorPin[i], INPUT);
pinMode(ledPin[i], OUTPUT);
}
}
void loop()
{
level = 0;
for(int i = 0; i < sensors; i++)
{
if(digitalRead(sensorPin[i]) == LOW)
{
digitalWrite(ledPin[i], HIGH);
level = sensors - i;
}
else
{
digitalWrite(ledPin[i], LOW);
}
}
Serial.println("Water level Warning");
switch(level)
{
case 1:
Serial.println("AT+CMGF=1");
delay(500);
Serial.println("AT+CMGS=\"your no.\"");//Change the receiver phone number
delay(500);
Serial.print("Aler Warning: High Level."); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
break;
case 2:
Serial.println("AT+CMGF=1");
delay(500);
Serial.println("AT+CMGS=\"your no.\"");//Change the receiver phone number
delay(500);
Serial.print("Aler Warning: Moderate Level."); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
break;
case 3:
Serial.println("AT+CMGF=1");
delay(500);
Serial.println("AT+CMGS=\"your no.\"");//Change the receiver phone number
delay(500);
Serial.print("Aler Warning: Low Level."); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
break;
default:
Serial.println("No water");
break;
}
delay(50);
}