#include "SIM900.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include "sms.h"
#define GSM_ON 9
#define GSM_RESET 8
SMSGSM sms;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
SoftwareSerial sim900(2,3);
int i;
int led = 10;
int valLed;
int ldr = A0;
int valorSensor;
boolean started=false;
char smsbuffer[160];
char n[20];
char c;
void setup(){
pinMode(led, OUTPUT);
pinMode(ldr, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
digitalWrite(led, LOW);
}
void SIM900power(){ //on / off the SIM
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9,HIGH);
delay(5000);
}
void SIM900reset(){ //is reset to SIM900
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, HIGH);
delay(5000);
}
void connect(){ //connects to the GSM network
if(gsm.begin(9600)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
if(started){
delsms();
}
}
void enviarSMS1(){
lcd.begin(16, 2);
lcd.print("dry soil please");
lcd.setCursor(0, 1);
lcd.print(" pump send : ON");
delay(5000);
sms.SendSMS("+", "sensor register . To light LED send ON");
Serial.println("\nSMS sent OK");
delay(15000);
}
void enviarSMS2(){
lcd.begin(16, 2);
lcd.print(" pump on to off ");
lcd.setCursor(0, 1);
lcd.print("send : OFF ");
sms.SendSMS("+", "led on . To delete send OFF");
Serial.println("\nSMS sent OK");
delay(15000);
}
void enviarSMS3(){
lcd.begin(16, 2);
lcd.print("the pump is OFF ");
lcd.setCursor(0, 1);
lcd.print("");
sms.SendSMS("+", "lED off");
Serial.println("\nSMS sent OK");
delay(15000);
}
void enviarSMS4(){
lcd.begin(16, 2);
lcd.print("SIM900 off");
lcd.setCursor(0, 1);
lcd.print("");
sms.SendSMS("+", "SIM900 off");
Serial.println("\nSMS sent OK");
delay(15000);
}
void enviarSMS5(){
lcd.begin(16, 2);
lcd.print("");
lcd.setCursor(0, 1);
lcd.print("");
sms.SendSMS("+", "sensor without registration . To clear LED send OFF");
Serial.println("\nSMS sent OK");
delay(15000);
}
void receberSMS(){
int pos=0;
if(started){
pos=sms.IsSMSPresent(SMS_ALL);
if(pos){
Serial.println("IsSMSPresent at pos ");
Serial.println(pos);
sms.GetSMS(pos,n,smsbuffer,100);
Serial.println(n);
Serial.println(smsbuffer);
if(!strcmp(smsbuffer,"ON")){
Serial.println("ON");
lcd.begin(16, 2);
lcd.print("pump is working ");
digitalWrite(led, HIGH);
delay(20000);
digitalWrite(led, LOW);
delay(50);
enviarSMS2();
}
if(!strcmp(smsbuffer,"OFF")){
Serial.println("OFF");
digitalWrite(led, LOW);
enviarSMS3();
}
if(!strcmp(smsbuffer,"SIMOFF")){
Serial.println("SIMOFF");
enviarSMS4();
SIM900power();
}
delay(1000);
delsms();
}
}
}
void delsms(){ //delete sms on the card
Serial.println("delsms");
for (int i=0; i<10; i++){ //do it max 10 times
int pos=sms.IsSMSPresent(SMS_ALL);
if (pos!=0){
Serial.print("\nFind SMS at the pos ");
Serial.println(pos);
if (sms.DeleteSMS(pos)==1){
Serial.print("\nDeleted SMS at the pos ");
Serial.println(pos);
}
else
{
Serial.print("\nCant del SMS at the pos ");
Serial.println(pos);
}
}
}
}
void loop(){
for(int valorSensor = 0; valorSensor < 1; valorSensor++)
{
valorSensor = analogRead(ldr);
valLed=digitalRead(led);
lcd.begin(16, 2);
lcd.print(" AUTOMATIC ");
lcd.setCursor(0, 1);
lcd.print(" GARDENING ");
delay(3000);
lcd.clear();
lcd.begin(16, 2);
lcd.print(" WAITTING ...");
delay(3000);
Serial.print("State sensor: ");
Serial.println(valorSensor);
delay(1000);
if(valorSensor>300 && valLed==LOW){ //tanah kering
while (1){
SIM900reset();
connect();
enviarSMS1();
delay(6000);
receberSMS();
break;
}
}
if(valorSensor<=300 && valLed==HIGH){ //tanah basah
while (1){
SIM900reset();
connect();
enviarSMS5();
delay(6000);
receberSMS();
break;
}
}
}
}
this code it send message "the soil dry" to phone and after i dont send something to gsm it wiil continue send message"the soil dry " 
help me to make the code send message for one time only .....
for example : the soil is dry and it send message to phone and stop ... after i send something to gsm it continue the code ....
i want the code stay function but only the message send one time
please help me