Send live location using a push button on emergency number

Hello.
I'm new here.
I want to make a project like that,
In an emergency situation, I pressed a push button so that my current location will be sent to my emergency number. For this project I use

  1. Arduino Uno R3
  2. GSM: Sim 800l
  3. GPS: Neo-6m
    I individually successfully run this as like first I push the button so messaged sent to the number and secondly, I can see my GPS location on the serial monitor. But I can't do this together. so can someone help me, please?

Gsm code :

#include <SoftwareSerial.h>    //Create software serial object to communicate with SIM800L
SoftwareSerial GSM(8, 9); //SIM800L Tx & Rx is connected to Arduino #8 & #9

char phone_no[]="+8801703139601"; //change +92 with country code and 3378655465 with phone number to sms

#define bt_M  A0 // Button1 Pin A0 use for Send Message
#define bt_C  A1 // Button2 Pin A1 use for Call

#define LED 2 // Led Pin D2 use for LED

char inchar; // Will hold the incoming character from the GSM shield

void setup(){// put your setup code here, to run once

Serial.begin(9600);//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)  
GSM.begin(9600);   //Begin serial communication with Arduino and SIM800L

pinMode(bt_M, INPUT_PULLUP); // declare bt_M as input
pinMode(bt_C, INPUT_PULLUP); // declare bt_C as input

pinMode(LED,OUTPUT); // declare LED as output
  
Serial.println("Initializing....");
initModule("AT","OK",1000);                //Once the handshake test is successful, it will back to OK
initModule("ATE1","OK",1000);              //this command is used for enabling echo
initModule("AT+CPIN?","READY",1000);       //this command is used to check whether SIM card is inserted in GSM Module or not
initModule("AT+CMGF=1","OK",1000);         //Configuring TEXT mode
initModule("AT+CNMI=2,2,0,0,0","OK",1000); //Decides how newly arrived SMS messages should be handled  
Serial.println("Initialized Successfully"); 

}

void loop(){

if(GSM.available() >0){inchar=GSM.read(); Serial.print(inchar); 
 if(inchar=='R'){inchar=GSM.read(); 
 if(inchar=='I'){inchar=GSM.read();
 if(inchar=='N'){inchar=GSM.read();
 if(inchar=='G'){  
    initModule("ATH","OK",1000); // this command is used for Call busy
    }
   }
  }
 }

else if(inchar=='L'){delay(10); inchar=GSM.read(); 
     if(inchar=='E'){delay(10); inchar=GSM.read();
     if(inchar=='D'){delay(10); inchar=GSM.read();

     if(inchar=='1'){digitalWrite(LED, 1); sendSMS(phone_no,"LED is On");}
else if(inchar=='0'){digitalWrite(LED, 0); sendSMS(phone_no,"LED is Off");}
     }
    }
  }
}


if(digitalRead (bt_M) == 0){sendSMS(phone_no,"Help me I'm in Danger . ");}
if(digitalRead (bt_C) == 0){callUp(phone_no);}

delay(5);
}



void sendSMS(char *number, char *msg){
GSM.print("AT+CMGS=\"");GSM.print(number);GSM.println("\"\r\n"); //AT+CMGS=”Mobile Number” <ENTER> - Assigning recipient’s mobile number
delay(500);
GSM.println(msg); // Message contents
delay(500);
GSM.write(byte(26)); //Ctrl+Z  send message command (26 in decimal).
delay(3000);  
}

void callUp(char *number){
GSM.print("ATD + "); GSM.print(number); GSM.println(";"); //Call to the specific number, ends with semi-colon,replace X with mobile number
delay(20000);       // wait for 20 seconds...
GSM.println("ATH"); //hang up
delay(100);  
}


void initModule(String cmd, char *res, int t){
while(1){
    Serial.println(cmd);
    GSM.println(cmd);
    delay(100);
    while(GSM.available()>0){
       if(GSM.find(res)){
        Serial.println(res);
        delay(t);
        return;
       }else{Serial.println("Error");}}
    delay(t);
  }
}

GPS code :

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

static const int RXPin = 4, TXPin = 5;// Here we make pin 4 as RX of arduino & pin 3 as TX of arduino 
static const uint32_t GPSBaud = 9600;


TinyGPSPlus gps;

SoftwareSerial ss(RXPin, TXPin);

void setup()
{
  Serial.begin(9600);
  ss.begin(GPSBaud);

 
}

void loop()
{
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}

void displayInfo()
{
  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  
  Serial.println();
}

Please select your code block, and wrap it with CODE TAGS

Everyone will love you, and send christmas cards. :flushed:

just to help out, code tags and more good stuff are described in How to get the best out of this forum

The reason for the use of code tags is e.g. char phone_no[]= ; with code tags it will be char phone_no[]=. Other reasons are that it's easier to read and easier to copy.

Select your first code and click the </> button to apply code tags; repeat for the secondcode. Next save your post

thank you soo much . Done. but can you help me plz?? how can i merged this two code so that i can get my gps location via message when i pressed the button . they both work individually perfectly

1 Like

Just do it . Can you help me plz?

1 Like

The GPS code will not detect if the GPS looses its fix and could therefore send out the incorrect (as in old) location.

What is the purpose of the project and where and how will it be used ?

Gps and Gsm code run perfectly when I try individual. I just want to merge two codes. I want to get my location when I pressed the push button to my contact number that's it.

Try a Google search on;

'Arduino how to combine sketches programs'

I already tried. I upload both of the codes in the post. If you help me I will really be grateful to you.

post your best attempt at merging the codes.

okkay

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.