How to limit the number of message that an Arduino sends to a phone without terminating it I just stayed on delay() since that is the only thing I know but the thing is delay() cannot be interrupted. What I'm trying to achieve with this code is: 


When the soilSensor detects moisture it would send a text message to a number only ONCE without terminating the program even if in the next loop the soilSensor is still detecting moisture. 
The soilSensor's delay is delay(60000) and we would still wait for while to finish the delay but what if in the middle of the soilSensor's delay(60000) there is a movement for just about 5 seconds? What to do so that the tiltSensor can overlap the soilSensor's delay and sends a message to a number? 


I want this program to run forever. Please help me! I needed this ASAP!

#include &lt;SoftwareSerial.h&gt;
SoftwareSerial SIM900(7, 8);
int led=22;

void setup()
{
  Serial.begin(9600);
  SIM900.begin(19200);
  pinMode(led, OUTPUT);
  delay(1000); 
}

void sendSMS1()
{
  SIM900.println("AT + CMGS = \"+************\"");
  delay(100);
  Serial.println("Water Detected");
  delay(100);
  SIM900.println("Water Detected"); 
  delay(100);
  SIM900.println((char)26); 
  delay(100);
  SIM900.println();
  delay(100); 
}


void sendSMS2()
{
  SIM900.println("AT + CMGS = \"+************\"");
  delay(100);
  Serial.println("Movement Detected");
  delay(100);
  SIM900.println("Movement Detected"); 
  delay(100);
  SIM900.println((char)26); 
  delay(100);
  SIM900.println();
  delay(100);  
}


void loop()
{    
  int soilSensor = analogRead(A0);
  int tiltSensor = analogRead(A1);

  if(soilSensor &gt;= 10)
  {
    digitalWrite(22, HIGH);
    Serial.println(soilSensor);
    sendSMS1();
    delay(60000);
  }
  else
  {
    digitalWrite(22, LOW);
    delay(60000); 
  } 

  if (tiltSensor &gt;= 100)
  {
    digitalWrite(led, HIGH);
    Serial.println(tiltSensor);
    sendSMS2();
    delay(60000);
  }
  else 
  {
    digitalWrite(led, LOW);
    Serial.println(tiltSensor);
    delay(60000);
  }
}
You use millis() to keep track of time and also prevent blocking. Replicating your program logic:

long soil_timer = 0;
long tilt_timer = 0;
char soil_flag = 1;
char tilt_flag = 1;

void loop() { 
    int soilSensor = analogRead(A0); 
    int tiltSensor = analogRead(A1); 

  if (soil_flag == 1) {
    if (soilSensor &gt;= 10) { 
      digitalWrite(22, HIGH);
      Serial.println(soilSensor);
      sendSMS1(); 
    }
   else { 
      digitalWrite(22, LOW);
    }
    soil_timer = millis();
    soil_flag = 0;
  }

  if (tilt_flag == 1) {
    if (tiltSensor &gt;= 100) { 
       digitalWrite(led, HIGH); 
       Serial.println(tiltSensor);
       sendSMS2();
    } 
    else { 
       digitalWrite(led, LOW); 
       Serial.println(tiltSensor);
    } 
    tilt_flag = 0;
    tilt_timer = millis();
  }
  if (millis() - soil_timer &gt;= 60000){
     soil_flag = 1;
  }
  if (millis() - tilt_timer &gt;= 60000){
     tilt_flag = 1;
  }
}