sim900 gsm module

Hello, my project requires to send a sms based on accelerometer reading. Example, if accelerometer reading is 395, send a sms. So, I need gsm code in "void loop()". I've been searching on the internet and I found all sms codes to be in "void setup". I wrote this code but there is no sms.

const int groundpin = 18; const int powerpin = 19; const int xpin = A3; const int ypin = A2; const int zpin = A1;

void setup() {

Serial.begin(2400); Serial.print("\r"); delay(1000);

pinMode(groundpin, OUTPUT); pinMode(powerpin, OUTPUT); digitalWrite(groundpin, LOW); digitalWrite(powerpin, HIGH); } void loop() {

if(analogRead(xpin) > 250) { Serial.print("AT+CMGF=1\r"); delay(1000); Serial.print("AT+CMGS=\"+91944xxxxxx8\"\r"); delay(1000); Serial.print("Test SMS \r"); //The text of the message to be sent delay(1000); Serial.write(0x1A); delay(1000); } else { Serial.print("AT\r"); } }

please help. If the SMS part of the code is in "void setup", sms is sent but not when in void loop.

Pin 18/19 cannot be used to power a GSM module! Use external 4V eg. cellphone battery.