Arduino code issue

There is a sump pump code that I recently found on line. But the issue that I am having is that once the sensor is submerge it send text message about every 10 seconds until you fix the submerge problem.

Using a GPRS (SIM 900) shield and a duemilanova board. I modified the code to xxxxxxxxxx as the recipient phone number.

Plus is it possible to add multi phone numbers so the maintenance team can receive the text message. Also I would like to add an emergency stop button in the code so when it is activated it also send a text message to the maintenance team.

#include <SoftwareSerial.h>

 SoftwareSerial mySerial(7, 8); //gprs shield attached to pins 7 and 8 for software serial connection

 const String phoneNumber = "xxxxxxxxxx"; //the phone number of the phone to send the text message to, remember to include the country code before the number

 const int sensorPin = 2; //the water sensor is attached to pin 2

 boolean flooded = false; //set the flooded variable to false

 boolean messageSent = false;

 void setup(){

   mySerial.begin(19200); //19200 is the GPRS baud rate, this must be fixed



   pinMode(sensorPin, INPUT);




 void SIMpower()

 // software equivalent of pressing the GSM shield "power" button


   digitalWrite(9, HIGH);


   digitalWrite(9, LOW);



 void loop(){ //we loop through this area

   if (digitalRead(sensorPin) == LOW){ //if the sensorPin is high, current is being passed into it, so the sensor must be submerged

     flooded = true; //the basement is therefor flooded

   } else if (digitalRead(sensorPin) == HIGH){ //otherwise if it has no current

     flooded = false; //the sensor isn't submerged

     messageSent = false; //we can reset the messageSend, so that if it becomes submerged again, we can end another text message



   if ((messageSent == false) && (flooded == false)){ //if we havent yet sent a message, and the sensor is submerged

     sendTextMessage(phoneNumber, "Basement Flooded"); //we send the text message

     messageSent = true; //we set messageSent to true so that we don't keep sending text messages (this woulld cost a lot of money)



 void sendTextMessage(String phone, String data){ //sends a text message to phone, containing data
 mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode


 mySerial.println("AT + CMGS = \"" + phone + "\"");//send sms message, be careful need to add a country code before the cellphone number


 mySerial.println(data);//the content of the message


 mySerial.println((char)26);//the ASCII code of the ctrl+z is 26



 delay(5000);                                  // give module time to send SMS

 SIMpower();                                   // turn off module


Water sensor.jpg

First point:-
It’s better if you post your code, rather than attach it. And it must be posted between code tags. </> in the “Reply” dialog.
When it’s just attached, we have to first create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the “Temp” folder and manually remove it. It’s much easier to just view the code in your post.

Second point:-
A link to the sump pump and to whichever shield you’re using would be helpful, along with your schematic diagram, so we can fully picture the setup.

once the sensor is submerge it send text message about every 10 seconds until you fix the submerge problem.

It sounds like you need to detect when the sensor becomes triggered rather than when it is triggered. Have a look at the StateChangeDetection example in the IDE.