GSM & GPS module integration.

Hi Guys,

I am working on GSM(SIM 800C) & GPS(Neo 6M) module integration. I am using Arduino 1.8.5 for the same. I have tested individual program for sending SMS through GSM module, also for getting location through GPD module and it’s working fine.

But now I want to make program like when user sends sms “ON” that time current location should send through SMS. I am using SoftwareSerial library it’s working for individual program.

Now GPS module should always get location automatically & when user send SMS “ON” it should send location SMS that time. Please check following program which I made but it’s not working.

//Program for getting GPS(Neo 6M) Module location & send through GSM(SIM 800C) Module Arduino 1.8.5
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
//4 3 for uno
static const int RXPin = 4, TXPin = 3; 
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial gpsPort(RXPin, TXPin);
SoftwareSerial gsmPort(10,11);
//variable for getting SMS
char incomingByte; 
String incomingData;
bool atCommand = true;
int led = 13;
int index = 0;
String number = "";
String message = "";
//Variables for storing Locations
double ltd=0;
double lng=0;

void setup(){
  Serial.begin(GPSBaud);
  gpsPort.begin(GPSBaud);
  gsmPort.begin(GPSBaud);
  initReceiveSMS();
}

void loop(){
  gpsPort.listen();
  while (gpsPort.available() > 0){
    gps.encode(gpsPort.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);
      ltd=gps.location.lat();
      lng=gps.location.lng();
      //sendSMS(gps.location.lat(),gps.location.lng());
      gsmPort.listen();
      receiveMessage();
    }
  }
  // blank line to separate data from the two ports:
  Serial.println();
  gsmPort.listen();
  while (gsmPort.available() > 0){
    delay(100);
      
      // Serial buffer
      while(gsmPort.available()){
        incomingByte = gsmPort.read();
        incomingData += incomingByte; 
       }
        
        delay(10); 
        if(atCommand == false){
          Serial.println("in false");
          receivedMessage(incomingData);
        }else{
          Serial.println("in else false");
          atCommand = false;
        }
        
        //delete messages to save memory
        if (incomingData.indexOf("OK") == -1){
          gsmPort.println("AT+CMGDA=\"DEL ALL\"");
          delay(1000);
          atCommand = true;
        }
        
        incomingData = "";
    }

}
void initReceiveSMS(){
    while(!gsmPort.available()){
      gsmPort.println("AT");
      delay(1000); 
      Serial.println("connecting....");
    }
    
    Serial.println("Connected..");  
    gsmPort.println("AT+CMGF=1");  //Set SMS Text Mode 
    delay(1000);  
    gsmPort.println("AT+CNMI=1,2,0,0,0");  //procedure, how to receive messages from the network
    delay(1000);
    gsmPort.println("AT+CMGL=\"REC UNREAD\""); // Read unread messages
    Serial.println("Ready to received Commands..");     
  }
  
void receivedMessage(String inputString){ 
   Serial.println("in receivedmessage"); 
  //Get The number of the sender
  index = inputString.indexOf('"')+1;
  inputString = inputString.substring(index);
  index = inputString.indexOf('"');
  number = inputString.substring(0,index);
  Serial.println("Number: " + number);

  //Get The Message of the sender
  index = inputString.indexOf("\n")+1;
  message = inputString.substring(index);
  message.trim();
  Serial.println("Message: " + message);
        
  message.toUpperCase(); // uppercase the message received

  if (message.indexOf("ON") > -1){
      Serial.println("Command:Send SMS.");
      sendSMS();
   }
          
   delay(10);
  }
void sendSMS()
{
    String smsValue;
    smsValue += F("your location is \nlat:");
    smsValue +=String(ltd,6);
    smsValue+= F("\nlong:");
    smsValue +=String(lng,6);
    gsmPort.listen();  
    //Serial.print(smsValue);
    gsmPort.println("AT+CMGF=1");
    delay(1000);
    gsmPort.println("AT+CMGS=\"+918237478379\"\r");
    delay(1000);
    gsmPort.println(smsValue);
    delay(100);
    gsmPort.println((char)26);//ASCII code for CTRl+z
    delay(1000);
    Serial.println("SMS sent successfully!"); 
}

Well, kudos for using code tags on your first post but "it's not working" is of course the most useless description.

What does it do, and how is that different from what you want it to do?