Combining codes for GPS(Neo6m), GSM(Sim900) and Motion sensor(SW420)

I have a code for sending GPS coordinates in form of Google Maps link that sends every 5 seconds, I also have this code for controlling LEDs via SMS, and a code for the Motion sensor for sending SMS automatically when it is triggered. I got all of them online and I kinda revised them and I tried combining all of them but they just won't work, I didn't get any errors and the wirings are also correct. I've searched online about this but I can't seem to find anything that can help me with this issue. I'm doing an Anti-theft vehicle system that can send the GPS coordinates when the SMS sent to the GSM contains "LOCATION" on it, "RING", "STOP" and "STATE" for making the led/lights on or off and knowing it's status, and lastly automatic sending of vehicle's location when the sensor is triggered. By the way I'm just new to programming so, I really need your help.

Here's the code for the "RING", "STOP", "STATE" thing.

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);
String textMessage;
String lampState = "off";

int aled = 4;
int bled = 5;

void setup() {
  pinMode(aled, OUTPUT);
  pinMode(bled, OUTPUT);

  Serial.begin(9600); 
  GPRS.begin(9600);

  delay(5000);
  Serial.print("GPRS ready.");
  
  GPRS.print("AT+CMGF=1\r"); 
  delay(100);

  GPRS.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
}

void loop(){
  if(GPRS.available()>0){
    textMessage = GPRS.readString();
    Serial.print(textMessage);    
    delay(10);
    textMessage.toUpperCase();
  } 
  if(textMessage.indexOf("RING")>=0){
    digitalWrite(aled, HIGH);
    digitalWrite(bled, HIGH);
    lampState = "on";
    Serial.println("Alarm set to ON");  
    textMessage = "";   
  }
  if(textMessage.indexOf("STOP")>=0){
    // Turn off relay and save current state
    digitalWrite(aled, LOW);
    digitalWrite(bled, LOW);
    lampState = "off"; 
    Serial.println("Alarm set to OFF");
    textMessage = ""; 
  }
  if(textMessage.indexOf("STATE")>=0){
    String message = "Alarm is " + lampState;
    sendSMS(message);
    Serial.println("Alarm state request");
    textMessage = "";
  }
}  

void sendSMS(String message){
  GPRS.print("AT+CMGF=1\r"); 
  delay(100);

  GPRS.println("AT + CMGS = \"+63*********\""); 
  delay(100);
  GPRS.println(message); 
  delay(100);
  GPRS.println((char)26); 
  delay(100);
  GPRS.println();
  delay(5000);  
}

And here's the code for sending GPS coordinates every 5 seconds

#include <SoftwareSerial.h>
#include <TinyGPS.h>

SoftwareSerial GPS(12, 11);
SoftwareSerial GPRS(7, 8);
TinyGPS neo6m;

void setup()
{
  GPRS.begin(9600);
  delay(500);
  GPS.begin(9600);
  delay(500);
  Serial.begin(9600);
}

void loop(){
  while (GPS.available()) {
    if (neo6m.encode(GPS.read())) {
      float latitude, longitude;
      neo6m.f_get_position(&latitude, &longitude);
      float lat = latitude;
      float lng = longitude;

      String meslat = String(lat, 6);
      String meslon = String(lng, 6);
      String com = ",";
      String link = "https://www.google.com/maps/?q=";
      String txt = link + meslat + com + meslon;
      Serial.println(txt);

      delay(5000);
      GPRS.print("\r");
      delay(500);
      GPRS.print("AT+CMGF=1\r");
      delay(500);
      GPRS.print("AT+CMGS=\"+63**********\"\r");
      delay(500);
      GPRS.print(txt);
      delay(500);
      GPRS.write(0x1A);
      delay(500);
    }
  }
}

and the code for the Sensor sending SMS when triggered

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);
boolean state, lastState;
int sw420 = 2;

void setup()
{
  pinMode(sw420, INPUT_PULLUP);
  state = digitalRead(sw420);
  lastState = state;
  
  GPRS.begin(9600);
  Serial.begin(9600);
  
  GPRS.println("AT+CMGF=1");
  
  delay(1000);
}

void loop()
{
  while(GPRS.available()) {
    Serial.write(GPRS.read());
  }

  lastState = state;
  state = digitalRead(sw420);
  
  if ( state != lastState ) {
    sendSMS();
  }
  delay(500);
}

void sendSMS() {
  Serial.print("Switch was turned ");
  Serial.println(state ? "on" : "off");
  
  GPRS.println("AT+CMGS=\"+63**********\"");
  
  delay(500);
  
  GPRS.print("Vehicle's alarm was triggered!");
  GPRS.println(state ? "on" : "off");
  GPRS.write( 0x1a );
  
  delay(500);
}

A big thanks in advance, I really need your help.

I got all of them online and I kinda revised them and I tried combining all of them but they just won't work

You have three sketches that work, and you posted them.

You have one that does something mysterious, but that is not what you want, that you didn't post. But, you want us to explain why the code we can't see doesn't do what you want.

Does that really seem likely to happen?

I just want to combine them all 3 and get the result that I wanted sir, which is to get the GPS coordinates sent via SMS when "LOCATION" is sent to the system, and also automatically send GPS coordinates via sms when the sensor is triggered sir.

I tried combining all of them

Why don't you post that code?

Yeah, I'm sorry sir, here...

#include <SoftwareSerial.h>
#include <TinyGPS.h>

SoftwareSerial GPS(12, 11);
SoftwareSerial GPRS(7, 8);
TinyGPS neo6m;

String textMessage;
String AlarmStatus = "off";
boolean state, lastState;
int sw420 = 2;

int aled = 3;
int bled = 4;

String crdnts;

void setup() {
  pinMode(aled, OUTPUT);
  pinMode(bled, OUTPUT);
  pinMode(sw420, INPUT_PULLUP);

  state = digitalRead(sw420);
  lastState = state;

  Serial.begin(9600);
  delay(500);
  GPS.begin(9600);
  delay(500);
  GPRS.begin(9600);

  delay(5000);
  Serial.print("System ready.");

  GPRS.print("AT+CMGF=1\r");
  delay(100);

  GPRS.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
}

void loop() {
  if (GPRS.available() > 0) {
    textMessage = GPRS.readString();
    Serial.print(textMessage);
    delay(10);
    textMessage.toUpperCase();
  }

  while (GPS.available()) {
    if (neo6m.encode(GPS.read())) {
      float latitude, longitude;
      neo6m.f_get_position(&latitude, &longitude);
      float lat = latitude;
      float lng = longitude;

      String meslat = String(lat, 6);
      String meslon = String(lng, 6);
      String com = ",";
      String link = "https://www.google.com/maps/?q=";
      String crdnts = link + meslat + com + meslon;
      Serial.println(crdnts);
    }
  }

  lastState = state;
  state = digitalRead(sw420);

  if ( state != lastState ) {
    AlarmSMS();
    SendCoordinates();
    digitalWrite(aled, HIGH);
    digitalWrite(bled, HIGH);
    digitalWrite(aled, LOW);
    digitalWrite(bled, LOW);
    digitalWrite(aled, HIGH);
    digitalWrite(bled, HIGH);
    digitalWrite(aled, LOW);
    digitalWrite(bled, LOW);
  }
  delay(500);

  if (textMessage.indexOf("RING") >= 0) {
    // Turn on relay and save current state
    digitalWrite(aled, HIGH);
    digitalWrite(bled, HIGH);
    AlarmStatus = "on";
    Serial.println("Relay set to ON");
    textMessage = "";
  }
  if (textMessage.indexOf("STOP") >= 0) {
    digitalWrite(aled, LOW);
    digitalWrite(bled, LOW);
    AlarmStatus = "off";
    Serial.println("Relay set to OFF");
    textMessage = "";
  }
  if (textMessage.indexOf("STATE") >= 0) {
    String message = "Alarm is " + AlarmStatus;
    sendSMS(message);
    Serial.println("Alarm state request");
    textMessage = "";
  }
  if (textMessage.indexOf("LOCATION") >= 0) {
    SendCoordinates();
    textMessage = "";
  }
}

void sendSMS(String message) {
  GPRS.print("AT+CMGF=1\r");
  delay(100);

  GPRS.println("AT + CMGS = \"+63***********\"");
  delay(100);
  GPRS.println(message);
  delay(100);
  GPRS.println((char)26);
  delay(100);
  GPRS.println();
  delay(5000);
}

void AlarmSMS() {
  Serial.print("Vehicle's alarm is triggered!");

  GPRS.println("AT+CMGS=\"+63**********\"");

  delay(500);

  GPRS.print("Vehicle's alarm is triggered!");
  GPRS.write( 0x1a );

  delay(500);
}

void SendCoordinates() {
  GPRS.print("\r");
  delay(500);
  GPRS.print("AT+CMGF=1\r");
  delay(500);
  GPRS.print("AT+CMGS=\"+63***********\"\r");
  delay(500);
  GPRS.print(crdnts);
  delay(500);
  GPRS.write(0x1A);
  delay(500);
}

You realize that two instances of SoftwareSerial can not listen at the same time, right? So, when you are listening to the GPS, you are NOT listening to the GPRS, and when you are listening to the GPRS, you are not listening to the GPS.

Can you suggest something that I can do sir?

Darren-June:
Can you suggest something that I can do sir?

Get an Arduino that has multiple hardware serial ports.

PaulS:
Get an Arduino that has multiple hardware serial ports.

Are you referring to the Arduino Mega sir? Sorry for the late reply sir.

Darren-June:
Are you referring to the Arduino Mega sir? Sorry for the late reply sir.

That's one of the Arduinos with multiple hardware serial ports. The Due has more than 2, also.

So which one will you suggest to me for this project of mine sir? And will my code work with this Arduino board sir?

Darren-June:
So which one will you suggest to me for this project of mine sir? And will my code work with this Arduino board sir?

I'd suggest the Mega. I think it has more than enough memory and speed for your project, and is easier to program, and has more support, than the Due.

Will my code work on the Mega sir? Or, are there any alteration to my code sir?

Darren-June:
Will my code work on the Mega sir? Or, are there any alteration to my code sir?

Yes, you need to change your code. Get rid of the SoftwareSerial instances. Connect the GPS and GPRS to RX1, RX2, or RX3 and TX1, TX2, or TX3, and use Serial1, Serial2, or Serial3 to read from/write to them, instead.

Okay. Thank you sir PaulS for the advises, I'll update you when I got the Mega and when I've changed my codes, and maybe ask you again for more advises and hints for my project.

Good day sir, I finally got the Arduino Mega, and tried uploading the code with modification regarding Serial Ports, but it does not seem to work.

#include <TinyGPS.h>

#define GPRS Serial1
#define GPS Serial2

TinyGPS Neo6m;

String TextMessage;
String AlarmStatus = "off";

int aled = 4;
int bled = 5;

void setup() {
  pinMode(aled, OUTPUT);
  pinMode(bled, OUTPUT);

  Serial.begin(9600);
  delay(500);
  GPRS.begin(9600);
  delay(500);
  GPS.begin(9600);

  delay(5000);
  Serial.print("SYSTEM IS READY!");
  GPRS.print("AT+CMGF=1\r");
  delay(100);
  GPRS.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
}

void loop() {
  if (GPRS.available() > 0) {
    TextMessage = GPRS.readString();
    Serial.print(TextMessage);
    delay(10);
    TextMessage.toUpperCase();
  }
  if (TextMessage.indexOf("RING") >= 0) {
    digitalWrite(aled, HIGH);
    digitalWrite(bled, HIGH);
    AlarmStatus = "on";
    Serial.println("Command: Alarm set to ON!");
    TextMessage = "";
  }
  if (TextMessage.indexOf("STOP") >= 0) {
    // Turn off relay and save current state
    digitalWrite(aled, LOW);
    digitalWrite(bled, LOW);
    AlarmStatus = "off";
    Serial.println("Command: Alarm set to OFF!");
    TextMessage = "";
  }
  if (TextMessage.indexOf("STATE") >= 0) {
    String AlarmStatusMessage = "Alarm is " + AlarmStatus;
    AlarmStatusSMS(AlarmStatusMessage);
    Serial.println("Command: Alarm status request!");
    TextMessage = "";
  }
  if (TextMessage.indexOf("LOCATION") >= 0) {
    CoordinatesSMS();
    Serial.println("Command: Coordinates request!");
    TextMessage = "";
  }
}

void AlarmStatusSMS(String AlarmStatusMessage) {
  GPRS.print("AT+CMGF=1\r");
  delay(100);
  GPRS.println("AT + CMGS = \"+63**********\"");
  delay(100);
  GPRS.println(AlarmStatusMessage);
  delay(100);
  GPRS.println((char)26);
  delay(100);
  GPRS.println();
  delay(5000);
}

void CoordinatesSMS() {
  while (GPS.available()) {
    if (Neo6m.encode(GPS.read())) {
      float latitude, longitude;
      Neo6m.f_get_position(&latitude, &longitude);
      float lat = latitude;
      float lng = longitude;

      String meslat = String(lat, 6);
      String meslon = String(lng, 6);
      String com = ",";
      String link = "https://www.google.com/maps/?q=";
      String coordinates = link + meslat + com + meslon;
      Serial.println(coordinates);

      delay(5000);
      GPRS.print("\r");
      delay(500);
      GPRS.print("AT+CMGF=1\r");
      delay(500);
      GPRS.print("AT+CMGS=\"+63**********\"\r");
      delay(500);
      GPRS.print(coordinates);
      delay(500);
      GPRS.write(0x1A);
      delay(500);
    }
  }
}