SIM900 GSM sms pir movement detector and sms alarm enable

Hi All - my first post :o

I am having mixed success with my UNO and ELECROW SIM900 GSM module linked to a remote (to activate my alarm through an external remote) as well as to receive an SMS when a PIR detector detects movement.

I have reused code from multiple sources (thank you to all those kind peeps who share)

I can get the receive SMS to work independently and the send SMS to work independently, but not together. I suspect it is something with the AT read command and where to put it/configure it!

please have a review and let me know if you spot anything.
Each purpose of the build is great, would just be nice to get it working together :slight_smile: Thank you

 Receive SMS and activate alarm description:
 - turn on GSM unit
 - be ready for SMS
 - when receiving an SMS "*on" it turns output pin10 high for 900ms 
 - deletes all SMS's  
PIR and send SMS description:
- Detect motion using PIR sensor - pin 11
- Activate the buzzer upon detection for 2000ms - pin 13
- Check if counter is less than 1, then send 1 SMS to a predefined mobile number set inside the program.  
- reset sms_count to zero when push switch goes high*/

#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7,8);

int led1 = 10; //output pin to turn on relay to activate remote which switches on alarm
int sensor = 11; //The output of PIR sensor connected to pin 11
int sensor_value; //variable to hold read sensor value from PIR pin 11
int push_switch = 12; // push button switch connected to pin 12
int push_switch_value; //variable to hold push switch value from pin 12
int buzzer = 13; // buzzer connected at pin 13
int sms_count = 0; //set sms counter to 0

void setup()
// turn on serial communication
 // set up the digital pins to control
 pinMode(led1, OUTPUT);
 digitalWrite(led1, LOW);
 pinMode(sensor,INPUT); // configuring pin 11 as Input
 digitalWrite(sensor, LOW);
 pinMode(push_switch,INPUT); // configuring pin 12 as Input
 digitalWrite(push_switch, LOW);
 pinMode(buzzer,OUTPUT); // configuring pin 13 as OUTPUT
 digitalWrite(buzzer, LOW);

//auto turn on SIM900
pinMode(9, OUTPUT); 

// turn on GSM serial communication to Arduino
SIM900.begin(19200); // turn on serial communication on SIM900
SIM900.println("AT+CMGF=1");  // set SMS mode to text mode

void loop()
Check_SMSReceive(); //subroutine to check if SMS received

Check_PIR();// subroutine to check sensor status 


Check_Reset(); // subroutine to check if alarm reset switch pressed or not


void Check_SMSReceive()  //Check to see if a character comes in from the cellular module...
SIM900.println("AT+CNMI=2,2,0,0,0"); // read contents of new SMS upon receipt to the GSM shield's serial out
Serial.println("Waiting for SMS...");
if(SIM900.available() >0) //If a character comes in from the cellular module...
   if (inchar=='*')
   if (inchar=='o')
   if (inchar=='n')
       digitalWrite(led1, HIGH);
      digitalWrite(led1, LOW);
       Serial.println( "Message received to Activate Alarm" );
       SIM900.println("AT+CMGD=1,4"); // delete all SMS

void Check_PIR()
sensor_value=digitalRead(sensor); // Reading sensor value from pin 11
if((sensor_value==HIGH) && (sms_count < 1)) // Checking if PIR sensor sends a HIGH signal to pin 11

 { digitalWrite(buzzer,HIGH);// Activating the buzzer 
 SendTextMessage(); // Function to send AT Commands to GSM module

void SendTextMessage()
  SIM900.println("AT+CMGF=1");    //To send SMS in Text Mode
  SIM900.println("AT+CMGS=\"+278########\"\r"); // change to the phone number you using 
  SIM900.println("Movement detected");//the content of the message
  Serial.println( "Movement detected" ); // print to serial monitor
  SIM900.println((char)26);//the stopping character
  sms_count++; // advance sms_count by +1

void Check_Reset()
push_switch_value=digitalRead(push_switch); // Reading sensor value from pin 11
if ((push_switch_value==HIGH) && (sms_count >= 1))sms_count = 0; // Reactivating the SMS Alert Facility
- reset sms_count to zero when push switch goes high*/


Functions named CheckXXX should return true or false. They should NOT be diddling with global variables.

I got as far as reading Check_SMSReceive(), and almost threw up.

That crap isn't even close to how to read serial data. delay(10) is NOT how you make the next character arrive. You should NOT be reading unless you KNOW that there is something to read. You should NOT read the next character only if the last one was the one you expected.