GSM Shield coding question

Hello,

the code below keeps sending the message to the cell phone non stop.
I want it to send the message only once, but cannot figure out the correct way.

void loop()
{

  reading = analogRead(ir);
  cm = pow(3027.4/reading, 1.2134);
  Serial.println(cm);


 if (cm < 16){
  delay(5000);
  
  // send the message
  sms.beginSMS(number);
  sms.print(msg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
  
}

else if (cm>16){
  break;
}
 }

Are yo7u checking the output from your conditional?

cm < 16

Are you putting this to serial monitor to ensure you are in fact getting the values you believe you should be getting?

On a side note… (I’m not sure where you are located)… but I have a GSM shield myself… that I have never played with.

(I never could figure out the best place and HOW to get a SIM card for this… that was affordable?)

What did you end up using?

(I’m located in the US)

but cannot figure out the correct way.

// Global
bool beenThereDoneThat = false;

// Add some stuff
 if (cm < 16)
 { // Down here, where it belongs
    delay(5000);
 
    // send the message
    if(!beenThereDoneThat)
    {
       sms.beginSMS(number);
       sms.print(msg);
       sms.endSMS();
       Serial.println("\nCOMPLETE!\n");

       beenThereDoneThat = true;
    }
 }

xl97:
Are yo7u checking the output from your conditional?

cm < 16

Are you putting this to serial monitor to ensure you are in fact getting the values you believe you should be getting?

On a side note… (I’m not sure where you are located)… but I have a GSM shield myself… that I have never played with.

(I never could figure out the best place and HOW to get a SIM card for this… that was affordable?)

What did you end up using?

(I’m located in the US)

yup looks like the readings are off sometimes, unstable readings. maybe a loose wire. However, when the readings are ok i still receive a ton of messages. i will get a new sensor and will check tomorrow.

the GSM shield i have is the same as the one in the link:
http://www.qkits.com/moreinfo.cfm/A000043

The SIM card size is the ol regular SIM card size (there is the regular size, nano, and micro). you could use your phone’s SIM card, but if yours is the nano or micro size you could just use an adapter to be able to plug it into your GSM shield.