GSM shield won't stop sending text messages

Hello guys, I need help.. I made a simple code for the GSM shield to send message to my mobile phone after digital pin2 (through A0 pin) has a HIGH value ,the code works fine, however, as long as the GSM is always ON, it also always send the same messages even digital pin2 has LOW value already.. I need help.................................................

#include <SoftwareSerial.h>
SoftwareSerial mySerial1(2, 3);
//GSM gsmAccess;
//GSM_SMS sms;

int lev1 = A0;// 1st level input
int alert1 = 2;//1st level output
int a1 = 850;   // minimum threshold level
int a2 = 876;  // maximum threshold level

void setup()
{
  pinMode(lev1, INPUT); // A0 as input
  pinMode(alert1, OUTPUT);// pin 2 as output
  mySerial1.begin(9600);
  Serial.begin(9600);
  delay(500);


}
void loop()
{
  //  for level 1:
 int value1 = analogRead(lev1);
  if (value1 > a1 && value1 < a2)
   {
    digitalWrite(alert1, HIGH);
     Serial.print("Level 1 = ");
    Serial.println(value1);
     delay(1000);
 }
 else
 {
   digitalWrite(alert1, LOW);
 }
  if (mySerial1.available()>0)
    Serial.write(mySerial1.read());
  
{
  mySerial1.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(500);  // Delay of 1000 milli seconds or 1 second
  mySerial1.println("AT+CMGS=\"+63__________\"\r"); // Replace x with mobile number
  delay(500);
  mySerial1.println("Hello World");// The SMS text you want to send
  delay(60000);
   mySerial1.println((char)26);// ASCII code of CTRL+Z
  delay(500);
}
  
}
  if (mySerial1.available() > 0)
    Serial.write(mySerial1.read());

  {
    mySerial1.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
    delay(500);  // Delay of 1000 milli seconds or 1 second
    mySerial1.println("AT+CMGS=\"+63__________\"\r"); // Replace x with mobile number
and so on ...

Which lines of code will be executed only when the test returns true and which will be executed regardless of the result of the test ?

Well basically its purpose is just to send the message if the test is true and I lack the codes to make the GSM shield to stop sending if A0 goes below and above the threshold values (a1 and a2)... Coz what happens now is that the GSM shield wont stop sending message coz it receives true, unless there'll be some codes to make it stop..

I understand what it is supposed to do, but what code is in the code block that will only be executed if the test is true ?

This one?

mySerial1.println("Hello World");// The SMS text you want to send
  delay(1000);
   mySerial1.println((char)26);// ASCII code of CTRL+Z
  delay(500);

doitabs:
This one?

mySerial1.println("Hello World");// The SMS text you want to send

delay(1000);
  mySerial1.println((char)26);// ASCII code of CTRL+Z
 delay(500);

No.
When

 if (mySerial1.available() > 0)

returns true then only

   Serial.write(mySerial1.read());

will be executed
Whereas

    mySerial1.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
    delay(500);  // Delay of 1000 milli seconds or 1 second
    mySerial1.println("AT+CMGS=\"+63__________\"\r"); // Replace x with mobile number
    delay(500);
    mySerial1.println("Hello World");// The SMS text you want to send
    delay(60000);
    mySerial1.println((char)26);// ASCII code of CTRL+Z
    delay(500);

will be executed each time through loop().

Put braces around the code to be executed when the test returns true so that it is not executed unconditionally each time through loop()

Can you help me? I'm not an expert in programming arduino. And I definitely don't know how to put braces.. Or what topic should I search to learn putting braces? I just need what area(s) do I have to look in the internet for this problem..

  if (mySerial1.available() > 0)  //if this is true
  {                               //execute the code in the pair of braces
    Serial.write(mySerial1.read());
    mySerial1.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
    delay(500);  // Delay of 1000 milli seconds or 1 second
    mySerial1.println("AT+CMGS=\"+63__________\"\r"); // Replace x with mobile number
    delay(500);
    mySerial1.println("Hello World");// The SMS text you want to send
    delay(60000);
    mySerial1.println((char)26);// ASCII code of CTRL+Z
    delay(500);
  }

Can I suggest that you always use a pair of braces to enclose the code to be executed when a test is true even if there is only one line of code.

doitabs:
Can you help me? I'm not an expert in programming arduino. And I definitely don't know how to put braces..

Braces is just another name for these curly bracket symbols: { }

Cue the discussion on what {} () and [] are called !

I tried it just now but I still keep on receiving text messages. I don't know if my idea is right but I'm thinking of adding a function that would limit the GSM shield in sending SMS, like say 3 messages every true values?

ok thanks...

Have you got it working now ?

Yeah, It's working..right now I'm looking on improving the codes, I'm looking for limiting the sent messages.. I'm constructing another set of codes, I hope this works..

Thanks a lot..

I'm looking for limiting the sent messages.

What do you mean by this ?

I was thinking of limiting my GSM shield to sending only 3 messages on every high result from pin2.

What is connected to pin 2 ?

pin 2 is my serial Rx and at the same time the output pin of my A0 input signal. Coz i have a separate circuit that produces 4vdc when i shorted the circuit's (the separate circuit) ground and input terminal. the 4vdc goes to A0 Arduino and I assigned D2 (pin 2) as output..

pin 2 is my serial Rx and at the same time the output pin of my A0 input signal

I have no idea what you mean by this.

There is something very odd about your program. Consider these lines of code

SoftwareSerial mySerial1(2, 3);

Pin 2 is used as the Rx line for SS

int alert1 = 2;//1st level output

Here you describe it as an output

 pinMode(alert1, OUTPUT);// pin 2 as output

Here you actually set it to be an output

So, is pin 2 an input (SS Rx) or an output ?

Correct me with the codes, I surely did it wrong coz I made D2 pin as Rx and at the same time set it as output pin of A0 input..