How to Send GPS Location Via SMS using GSM and Arduino?

The main three components in this project are GPS (Global Positioning System) module, GSM Module, and an Arduino Uno. Here we are sending the live coordinates received by the GPS receiver module to a mobile phone via SMS using the GSM module.

GPS Receiver Module

A GPS receiver module is a device that receives information from GPS satellites and obtains the geographical position of the device.

GPS Module Arduino Connection

Pin configuration as in the below code and given circuit diagram.

Arduino Pin GPS Module Pin
Tx (Digital Pin 5 ) Rx
Rx (Digital Pin 4) Tx
GND GND

GSM Module

gsm module
A GSM module is a device used to establish communication over a mobile network. GSM or GPRS Module requires a SIM card to operate or to register a connection with the network operator or service provider.

GSM module Connection with Arduino

Arduino Pin  GSM Module Pin
Tx (Digital Pin 3) Rx
Rx (Digital Pin 2) Tx
GND GND

Refer the tutorial links given below for detailed working, codes, and interface of the GPS and GSM modules with Arduino.

gps gsm arduino, gps sms, send gps

The GPS receiver obtains the data as a whole NMEA format text. Only the latitude and longitude coordinates are taken from it; using the Arduino TinyGPS library. Then the GSM module sends SMS to the number specified in the code.

This code is useful for GPS and GSM projects like Vehicle Tracker and other Arduino based live location sharing or tracking devices, similar prototypes etc.

The switch input based GPS needs a manual action to operates or send SMS. It is to just send the location by ourselves. By just simple modifications the circuit can be integrated with a wide range of sensors to detect flame, vibration, or similar devices to automatically operates on specific events. Such as, using with a flame detector sensor to automatically send the location of the fire accident, vehicle accident detection system to send the location of accident vehicle to rescue team, etc…

Arduino code for sending GPS Longitude and Latitude coordinates on switch press.

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

int state = 0;
const int pin = 9;
float gpslat, gpslon;

TinyGPS gps;
SoftwareSerial sgps(4, 5);
SoftwareSerial sgsm(2, 3);

void setup()
{
  sgsm.begin(9600);
  sgps.begin(9600);
}

void loop()
{
sgps.listen();
  while (sgps.available())
  {
    int c = sgps.read();
    if (gps.encode(c))
    {
      gps.f_get_position(&gpslat, &gpslon);
    }
  }
    if (digitalRead(pin) == HIGH && state == 0) {
      sgsm.listen();
      sgsm.print("\r");
      delay(1000);
      sgsm.print("AT+CMGF=1\r");
      delay(1000);
      /*Replace XXXXXXXXXX to 10 digit mobile number &
        ZZ to 2 digit country code*/
      sgsm.print("AT+CMGS=\"+ZZXXXXXXXXXX\"\r");
      delay(1000);
      //The text of the message to be sent.
      sgsm.print("Latitude :");
      sgsm.println(gpslat, 6);
      sgsm.print("Longitude:");
      sgsm.println(gpslon, 6);
      delay(1000);
      sgsm.write(0x1A);
      delay(1000);
      state = 1;
    }
  if (digitalRead(pin) == LOW) {
      state = 0;
    }
      delay(100);
  }

If we need to track the location of a moving device from a distant place or monitor the position of an object at a regular interval of time it can be obtained by just removing the  “if” condition to send SMS, instead just add time delay of few seconds or minutes. Then you can receive the current location of the receiver at fixed intervals.

To receive the SMS in a URL format to open directly on google maps the above message code can be replaced with,

      sgsm.print("https://www.google.com/maps/?q=");
      sgsm.print(gpslat, 6);
      sgsm.print(",");
      sgsm.print(gpslon, 6);

The resultant google map website address received as SMS will be, https://www.google.com/maps/?q=27.988139,86.924974 (GPS coordinate location @ ) which takes you directly to the map.

Arduino code for Sending GPS Location by SMS Request
#include <SoftwareSerial.h>
#include <TinyGPS.h>

float gpslat, gpslon;

TinyGPS gps;
SoftwareSerial sgps(4, 5);
SoftwareSerial sgsm(2, 3);

void setup()
{
  sgsm.begin(9600);
  sgps.begin(9600);
}
void loop()
{
sgps.listen();
  while (sgps.available())
  {
    int c = sgps.read();
    if (gps.encode(c))
    {
      gps.f_get_position(&gpslat, &gpslon);
    }
  }
sgsm.listen();
    if (sgsm.available() > 0) {
      String    c = sgsm.readString();
      c.trim();
      if (c.indexOf("GET-GPS") >= 0) {
        sgsm.print("\r");
        delay(1000);
        sgsm.print("AT+CMGF=1\r");
        delay(1000);
        /*Replace XXXXXXXXXX to 10 digit mobile number &
          ZZ to 2 digit country code*/
        sgsm.print("AT+CMGS=\"+ZZXXXXXXXXXX\"\r");
        delay(1000);
        //The text of the message to be sent.
        sgsm.print("Latitude :");
        sgsm.println(gpslat, 6);
        sgsm.print("Longitude:");
        sgsm.println(gpslon, 6);
        delay(1000);
        sgsm.write(0x1A);
        delay(1000);
      }
  delay(100);
    }

In the first code, the arduino checks the switch input to send the location. Here we have replaced the condition with a program to check the SMS received and send GPS location if the SMS contains the word “GET-GPS”. So by just sending an SMS with the text “GET-GPS” to the GSM module, the GPS location will be sent to the number specified in the code.

You may also like...

388 Responses

  1. Ganesh Ram says:

    Which mobile sim should i use??
    Either 2G or 3G or 4G Sim ??

  2. Ganesh Ram says:

    Really thank you so much this code really works. whereas coding from other websites is not helping us and we gained some knowledge through this. We need one more help. we got latitude and longitude in a mobile phone using that how can I plot in a map automatically in a mobile phone.

  3. Obaidullah Khan says:

    Hi,

    Instead of a switch can we get the GPS Coordinates by sending the sms to the tracker

  4. Ganesh Ram says:

    Actually we are having ARDUINO MEGA , GPS , GSM MODULE. We tried our best with the following code.

    SoftwareSerial sgps(4, 5);
    SoftwareSerial sgsm(2, 3);

    But we can’t get output in mobile. So could you please post the exact PINNUMBER which i can use in the code to get output in mobile.

    Sir/Madam it is enough if you just edit and post the correct pin number

  5. Harika says:

    What is the value of the resistor used for the connection?Plss reply

  6. Harika says:

    Okk thankyou soo much..Really helped me alot..We got the output in terms of latitude and longitude …Still need to interface LCD to display messages like sms sent and also latitude and longitude….Please help how to modify the code for it…

  7. Ankita says:

    Instead of a switch can we get the GPS Coordinates by sending the sms to the tracker

    • admin says:

      yes, you can. Just need to add some code for receive and process the SMS.

      • Nurul Fitriah says:

        hi sir, how i should do that, do you have something that I can refer to? My project same as yours but I dont wanna use switch. Please help me sir.

        • admin says:

          Just remove or replace the if condition to check the switch state. Could you explain more about your requirement?

  8. Anjali says:

    why i am not getting anything on serial monitor
    and sir i am using gsm sim800l evb,tiny gps and arduino uno
    today is my project submission will you plzz help as fast as possible..plzz sir

    • admin says:

      If you are referring to the above code in this article, it has no code to display in the Arduino serial monitor. It used only software serial to receive data from the GPS module and Send the data via SMS through GSM.
      If you are trying to display the serial data send and receive by these two modules, add “Serial.print” after every sgsm.print the same as it is used.
      Refer : https://mechatrofice.com/arduino/arduino-serial-monitor-control

  9. Pubudu Ranawaka says:

    dear admin,
    can you tell me how can i do this project with out pressing button?(send location)

    thank you

    • admin says:

      Just remove the if condition “if (digitalRead(pin) == HIGH && state == 0)” or replace with some other conditions if you want to add something else. If removed, then the code starts to send location continuously. You can add extra time delay to send data at fixed intervals.

  10. Pubudu Ranawaka says:

    dear admin,

    i have get your second code(that send a sms and get location). i have followed your steps,and send as sms to my GSM module as you mention GET-GPS. but didn’t get reply.why is that?
    thank you.

  11. Paul says:

    Which kind of Arduino were you using?

  12. Shinae says:

    I exactly copied your code… But the led of tx doesn’t blink and I get nothing when I send an sms to the sim.
    I’m using sim 800L , arduino uno and a gps neo6M… I can’t figure out where the problem is “knowing that both sim and gps are working perfectly when used separately”
    Please help …

    • admin says:

      Add serial.print() and check whether up to what stage it is getting values.

      • Ivan says:

        Hi sir! Can you please show us the schematic diagram if we used sim800l and neo 6m instead of sim900? Thank you in advance sir.

        • admin says:

          There is no difference in the schematic diagram using a SIM800L instead of SIM900. Both are using same TTL serial communication using pins TX/RX. Connect the same digital pins used for SIM900 with arduino to the corresponding TX, RX, GND of SIM800L.
          Refer the above link – Interfacing sim800 / sim900A GSM module with arduino.

  13. faisal says:

    Bro the code from sending location using sms is not working.
    because, the gsm module dont recive any msg.
    what can i do now plzzz help me in this regard.

  14. Aashish says:

    Admin can you send me the external power supply value and connection because gsm not connecting to network it blink every second and after some seconds it stops and then again repeating the process

    • admin says:

      The module requires a considerable amount of amperes, it may use up to 2A while transmitting the data, so use supply which has an ampere of 1.5-3A.
      If you are using a GSM module with an inbuilt voltage regulator for the input of 12V, then use a 12V DC adapter (to 12V plug) or any 12V supply (to 12V pin). If the module has any 3.3V or 5V input pin then connect a supply of same voltage.

  15. Robin says:

    Admin, Does this code work for every sim network??

    • admin says:

      2G, 3G, and 4G sims work with the GSM module but the sim should support 2G. Because the module works as 2G.
      It does not work with 4G SIM that works only on LTE and VOLTE.

  16. Chawe says:

    Hi, does the code work well with sim800l, Ublox neo 6m gps module and Arduino uno? Or I need to make some modifications somewhere??

    • admin says:

      Yes, it does. For GSM module no library is using, only AT commands through software serial. And for the GPS we are using a TinyGPS library that is for modules using NMEA standard;neo6m uses NMEA standard. Hence, it would work.
      Also, you can try with a TinyGPS++ library.

  17. jayakrishna says:

    Can we send the message on regular intervals ?

    means, send a location message on every hour / 30 minutes ?

    • admin says:

      Yes, you can. You need to remove the “if” condition and add a time delay. Then the SMS will be sent after every interval.
      You can either use delay(), condition with millis() or an RTC (real-time clock) to set time duration.

  18. Nek says:

    Hi the code works the problem is whenever I add the software serial for the GPS the sending message function works but as for the receiving the module cant receive but i tried removing the serial number for gsm edited it with words if i receive GET-GPS i will print a certain word and it works. I wonder why It could send but cant receive. is it about baudrates?

  19. Nek says:

    Here is the code i manually debugged the SendMessage() function works while the Receive doesn’t.
    #include #include
    float gpslat, gpslon;TinyGPS gps;
    SoftwareSerial GPS(5, 6);SoftwareSerial SIM900A(10,11);
    void setup(){
    SIM900A.begin(9600);GPS.begin(9600);// Setting the baud rate of GSM Module
    Serial.begin(9600);// Setting the baud rate of Serial Monitor (Arduino)Serial.begin(9600);
    Serial.println (“SIM900A Ready”); delay(100);
    Serial.println (“GPS Ready”);delay(100);
    Serial.println (“Type s to send message or r to receive message”);
    }void loop(){
    while (GPS.available()){int c = GPS.read();
    if (gps.encode(c)) {gps.f_get_position(&gpslat, &gpslon);}}
    if (Serial.available()>0){
    switch(Serial.read()){
    case ‘s’:SendMessage(); break;
    case ‘r’: RecieveMessage(); break; }
    if (SIM900A.available()>0)
    Serial.write(SIM900A.read());
    }void SendMessage(){
    Serial.println (“Sending Message”);
    SIM900A.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
    delay(1000);
    Serial.println (“Set SMS Number”);
    SIM900A.println(“AT+CMGS=\”+639673894902\”\r”); //Mobile phone number to send message
    delay(1000);
    Serial.println (“Set SMS Content”);
    SIM900A.println(“https://www.google.com/maps/?q=”);
    // SIM900A.println(“latitude”);
    SIM900A.println(gpslat, 6);
    SIM900A.print(“,”);
    //SIM900A.println(“longitude”);
    SIM900A.println(gpslon, 6);
    delay(100);
    Serial.println (“Finish”);
    SIM900A.println((char)26);// ASCII code of CTRL+Z
    delay(1000);}
    void RecieveMessage(){
    SIM900A.println(“AT+CNMI=2,2,0,0,0”); // AT Command to receive a live SMS
    delay(1000);
    Serial.write (“Unread Message done”);
    }

    • admin says:

      Did you try the code to send only, is that working? (code in the post to just send), without using the option to send – void SendMessage() and receive – void RecieveMessage().

  20. Nek says:

    I think the softwareserial of the GPS disables my Receiving function. Can I have an advice admin.?

  21. RJ says:

    Hi im using arduino Mega 2560 i tried changing baudrates 4800 to 9600 my GPS type is Neo 7m. But what i get for both is all zero GPS(11,10) GSM(12,13)

    • admin says:

      Did you tried the GPS alone or used the GPS directly to serial monitor to check whether the module can receive data in NMEA text.

  22. sash says:

    i am getting lat and long as ZERO in sms.i am using sim800l and neo 6m gps module

    • admin says:

      Did you get the right lat and long values on the serial monitor?

      • Sash says:

        S I got it when gps is interfaced with arduino nano separately…but getting zero in sms when uploading this code …

      • gaurav upase says:

        no could not see anything

        • Matija says:

          Hi, did you managed to fix it? I am getting the same thing. First, with a button I am getting the correct coordinates. Than I changed to trigger a message with sms, didn’t work. I changed the code a little, now I am getting a response, but with lat and long as just 000000. Is there a solution to fix it? Thank you

      • Godswill says:

        Good morning Admin.
        Please I need the code that can send message with button pressed and when SMS is sent.

        Secondly, why is the Rx LED on Ardiouno Uno not blinking to show it’s getting reception from the GPS module when I uploaded the code for button triggered for SMS.

        I’m new to this, help me
        Thank you..

        • admin says:

          use the code given under “Arduino code for sending GPS Longitude and Latitude coordinates on switch press”.
          Rx will not blink when the GPS module gives a signal because it is not connected to default serial pins, RX & TX.

  23. sasi says:

    Arduino: 1.8.9 (Windows 7), Board: “Arduino/Genuino Uno”
    C:\Users\user\Desktop\sketch_sep19a_LAS\sketch_sep19a_LAS.ino: In function ‘void loop()’:
    sketch_sep19a_LAS:40:1: error: a function-definition is not allowed here before ‘{‘ token
    {^sketch_sep19a_LAS:46:1: error: a function-definition is not allowed here before ‘{‘ token
    {^sketch_sep19a_LAS:77:3: error: expected ‘}’ at end of input
    } ^
    exit status 1
    a function-definition is not allowed here before ‘{‘ token

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

  24. Nafla says:

    how can i programed with water level sensor for example if the water arose to specific percentage ex(30cm) then the action is “send the location” to the android application.

  25. akhona says:

    my email is akhona.kaizer@gmail.com i tried to send you an email but seems like your email is incorrect

  26. bhushan says:

    hey I am using sim800a and neo 6m
    but I am not receiving back
    I have used your code exactly
    plz reply asp

  27. admin says:

    Is this a completed code or you are getting an error?

  28. Akshith says:

    can u please give the code without using a switch .

  29. rahul says:

    hi can you suggest me the best reliable gps module for tracking vehicles in india and also can we attach some sensor’s and relay to control thr ignition of the vehicle using your code ?

  30. bhargav says:

    iam getting ????? in serial monitor….
    iam using same code in nano
    while iam checking gps before if condition iam getting ???? i tried with differet baud rates but not got thegps coordinates

    • admin says:

      Try the GPS module directly with any serial terminals and make sure it is receiving signals.
      And also make sure that the Arduino serial communication is working fine.

  31. Sanjeev Kumar says:

    Hello Admin,
    Thank you for providing the code. Although code is working fine but one problem I am facing is that when ever I am clicking on the message it directly linked with my phone’s Google map and is showing my current location instead of message coordinate position. Please help
    Thank you in advance.

    • admin says:

      Just change the default option on your phone. And try to open with any browser (or directly copy paste the link to URL bar).

  32. Darshini says:

    Hi, can I use Arduino Nano for this? Or only Uno / Mega are usable?

    • admin says:

      No, you can use with any Arduino boards. But, the circuit connections and declared pin numbers, etc need to be modified in respect to the arrangement.

  33. Pranilash says:

    Should the sim inserted in the GSM Module should be recharged ?

    • admin says:

      It should be an active SIM card to register with the ISP. And need to be charged for SMS and call as per ISP charges.

  34. Ayesha says:

    Hlw, i am using GSM 800L module ..is it ok? because i am not getting any massage in my mobile.

    • admin says:

      GSM800L module is ok to use with arduino. Try the module directly with any serial monitors and make sure it is working fine.

  35. PRANILASH says:

    Thank You very much Admin……
    Your code really helped me alot……….

  36. david says:

    Hi sir, I would like to merge press button and sms request to send gps location when either press button or receive sms request. How can I merge all from your code above?
    Thank you so much

    • admin says:

      you can combine both if condition with an ‘or’.
      if ((condition1-switch press) || (condition2-sms request)) {
      //send sms
      }

  37. thakshila says:

    how can i get gps location throught A6 gprs gsm module.Is that location also get to the mobile through SMS.

  38. Wilter.Flow says:

    Your code gives me latitude and longitude of 0.000000 even though it is outside.
    How will it send me the true coordinates of my location?

  39. John Lloyd says:

    Hello sir! Good Morning! I would like to ask if you have schematic diagram or circuit for the “Arduino code for sending GPS Longitude and Latitude coordinates on switch press.” along with its resistor values if it has. Is it possible to ask for it and send it to my email? Thank you very much and I appreciate everything that you have done for this wonderful tutorial!

  40. Rishi Netha says:

    Hello,
    what is the best way to send a message from Arduino to register mobile and how to receive the message to turn off the particular thing which is attached to the Arduino board?
    Can you please email me the process and required things to make this project successful and the mail id is rishinetha@gmail.com, thanking you.

  41. r.sai sankar rao says:

    sir/madam can i replace the switch with “Ultrasonic Distance Sensor (HC-SR04)” to get the same output ,please respond as soon as possible
    thank you

  42. emily says:

    hi i am trying to use this for an 8th grade science project could you please tell me where to find the gsm module?

  43. K.shiva prasad reddy says:

    How to given power supply to the circuit and what is the volt rage

    • admin says:

      You can provide an external power supply because the GSM module requires a considerable amount of power. you can either connect a 12V supply to board 12V connector or 5V to 5V pins.

  44. K mahipal reddy says:

    Sgsm doesn’t name type

    • admin says:

      It means no definition for that identifier visible to the compiler.
      Did you have “#include SoftwareSerial.h” or properly declared sgsm ?

  45. Mahipal Reddy says:

    Can I use 800L GSM module

  46. Nataraj says:

    I have received sms to my phone….but it displays latitude 0.00000 and longitude0.00000
    Iam using neo 6m gps
    Please reply immediately

  47. nithish says:

    i am using aurdino atmega 2560 .in this it consists of 4 tx ins and 4 rx pins so i can give the connections of gsm and gps module tx and rx pins to that instead of using digital pins

  48. K.shiva prasad reddy says:

    same code for 800l GSM module and connection are also Same sir and also if I use 800l GSM module there will any problem with module sir

  49. Prahatheesh says:

    I have used your code but I am getting the co-ordinates as zero

  50. Shiva says:

    Sir In my gps serial monitor nothing is not coming but position led is bilking for every one second plz help tomorrow is my project submission plz help

  51. Priya says:

    If I want to use a touch sensor instead of switch, how will the coding be? What changes do I need to do?

    • admin says:

      If you are using a Digital capacitive sensor touch switch then make no change to the code, just connect the output of the sensor to input pin 9. Because the output of a digital touch switch will be the same as a switch, HIGH state when touching and LOW state during no touch.
      Or if you are using a piezo or similar component that generates an analog output then you can connect it to an analog pin and check if input reaches greater than a threshold value; if(A0 > thresoldvalue && state==0){…}.

  52. Leonardo Pag-iwayan says:

    Hi admin I’ve checked gps module separately but it’s working but if I will use the code above it returns 0 values when in print to serial monitor.

    This is my initianilzation:

    TinyGPS gps;
    SoftwareSerial sgps(4, 3);
    SoftwareSerial sgsm(7, 8);

    my email is Lpagiwayan@gmail.com

  53. Amul Dhungel says:

    Why the vcc of of gsm is not connected to anything and vcc of gps too

    • admin says:

      Because both modules are powered with external supplies, either 12V to its connector or +5V to pins. But all boards should have a common GND connection.

      • Amul Dhungel says:

        ok for now i want to give 5v to both gps and gsm.and resisotr one point is already connected to 5v pin of aurdino so how can i give it 5v to both gsm and gps

      • danica says:

        i tried to connect it to the 5v of arduino nano both gps and gsm are blinking but not sending the location and also im using a sim800l. also may i ask if what do you mean by external supply ?is it the battery? hope to answer we need because we will use it for our research subject

        • admin says:

          An external supply can be any DC power source, a battery, SMPS, etc. It should be able to supply enough amount of amperes that is required to power the GPS and GSM modules.

          • danica says:

            Can we use lm2596 and a dc adapter and a 9v battery for the sim800l gsm module or we can we can directly use lm2596 and 9v battery?Can you also give us a code sir?

          • admin says:

            If you are using an LM2596 DC-DC Buck Converter then you can use a dc adapter or a 9V battery as input to obtain a 5V output.

          • danica says:

            I use LM2596 DC-DC Buck Converter for sim800l, i connect the 5v of gsm to lm2595 and the gnd of gsm also….the gps and gsm are both blinking but when i press the switch it suppose to send message but it is not sending…i also try the gsm and gps if working individually and they are working individually…i hope you an give us a code and a circuit diagram if i use lm2596 to check 🙂

          • admin says:

            Use the same circuit but this time add an LED to any of the digital pins and insert the code to blink the LED inside in the “if” condition portion of the existing code as shown below,
            …..
            if (digitalRead(pin) == HIGH && state == 0) {
            digitalWrite(6,HIGH); // eg:- Connect LED to pin 6
            delay(1000);
            digitalWrite(6,LOW);
            sgsm.listen();     
            sgsm.print(“\r”);
            …..
            Then while operating the circuit press and hold the push switch till the LED blink once.
            Also, make sure the input source of the buck converter is able to source more than 2 amperes of current.

  54. Deepa says:

    What do you mean as all boards should have a common Gound, as you answered above?

    If there’s external supply of V to GSM & GPS, then shouldn’t the Ground of GSM & GPS be connected to Ground of the external supply? If not to external supply, why to Arduino’s Ground?

    • admin says:

      The GND of both modules should be connected to the GND of external supply and Arduino. A common GND share GND of all power supplies.
      For serial communication, the Rx and Tx of both modules are referenced with a logic ground. Hence a common GND with supplies is required to communicate modules that are powered by different sources.

      • Amul Dhungel says:

        can i connect the above circuit design gps and gsm and button to the same 5v pin slot of aurdino?

        • admin says:

          Modules draw a considerable amount of power; depending on the module type. Hence, both modules couldn’t get sufficient power if connected to arduino 5V pin and also it may damage the Arduino board. So it is better to use an external supply.

      • Deepa says:

        Both the modules are connected to external 5V supplies right?? not to Arduino’s 5V??

  55. Mahipal Reddy says:

    I use 800l GSM module for above project but msg not coming and I also test separatrlybot GPS and 800l GSM there working properly but combination is not working properly plz help sir

  56. Sheet says:

    Sir, I need code of interfacing of gps neo 6m
    0-001 ,gsm900A , 16*2 lcd display, and ultrasonic sensor. Please help mi .

  57. Sam says:

    I am working on project railway track crack detection vehicle but I am unable to interface GPS GSM and ultrasonic sensor . In this project ultrasonic sensor detect crack and coordinates of crack sent through message . Please sir help mi I have submittion.

  58. holmes says:

    can i any one help me modify this code and add vibration sensor setting instead of switch
    vibration sensor module is sw420

  59. Sheet says:

    .Will you please send mi code for this project. Railway track crack detection vehicle in which ultrasonic sensor detect crack by not receiving echo and coordinates of crack are sent to registered number through GPS GSM I am using GSM sim900A, GPS neo 6M 0-001 .
    Please sir help mi I have submittion and I am not getting code from anywhere.

    • admin says:

      You have to add additional lines for the ultrasonic distance measurement. Refer ultrasonic interface, https://mechatrofice.com/arduino/ultrasonic-distance-measurement ; integrate the code with the here code.
      Replace the if condition in the code that checks the switch input state, with the ultrasonic output value to check if it is below the normal echo value.
      if (ultrasonic_distance < normalvalue) {    sgsm.print("\r"); .....

      • Sheet says:

        Sir, thanks for your response . Code is working but it shows error that “multiple libraries were found ” . With this it is generating file with the extension “.elf” instead of hex file . How can I fix it ??

        • admin says:

          Check your Arduino library folder if multiple library files are existing; previous versions or similar types.

  60. Saana says:

    Thanks very much. the code work perfectly well for me. I try to print the date and time along side the location but don’t know how to. Please I need your help.

    Thanks once more

  61. Norasyikin says:

    Hello sir, i already try the code that your given, it has no error,,but when i try it did not send the location to my mobile phone..i already try it separately . Sir can you help me..

  62. Benjamin says:

    Hi, will this work if I use a sim800l?

  63. Peter parker says:

    I’m not getting the circuit diagram can any plz elaborate the connection plzzz

  64. Sash says:

    What changes should be made to use this code with a Standalone Atmega328p uc.

  65. gaurav upase says:

    I am getting lat and long as ZERO in SMS.I am using sim900l and neo 6m GPS module and nothing in serail mountor

  66. tarun baghel says:

    thank you this circuit is working thank you so much

  67. Priya says:

    Can you please help me with complete Arduino code that sends GPS location to an Android phone via Bluetooth Hc-42 module?

    And is there any specific/suggested app I need to download in order to receive (or store) the code?

  68. HARESHA says:

    hello sir, can i send those longitude and latitude to a web server using sim900 GPS/GPRS shield with Arduino

    • admin says:

      Yes with GPRS you can connect to a web server by TCP/IP protocol and send longitude and latitude values.

  69. Qq says:

    hello, i using arduino mega, gps and gsm module
    but i cannot get the message in phone

  70. Emmanuel Simpson says:

    hi sir, your code is running well, but i’m getting o.00000 values for both latitude and longitude, can i know how to fix it?

    • admin says:

      Check GPS separately. Make sure the variables have the values of GPS coordinates; try to print the values of the variables in the serial monitor.

  71. sanath says:

    how to write land phone caller id facility indicate Arduino programed pls help me

  72. Aung myo htet says:

    When I click bushbutton. I cannot receive sms always why

  73. AungMYO HTET says:

    HI Sir
    I want to send SMS with google link but I cannot receive SMS when I try your code2 .please send me coding for SMS with google link. Thankyou sir And I do not supersede your coding2 in your coding1.

    Thank you

  74. AungMYO HTET says:

    HI sir
    please send me coding fully for SMS with Google map link?
    Thank You

    • AungMYO HTET says:

      I can not understand your coding2 with Google map and what if the function is removed in coding 1.
      Please explain to me.

      • admin says:

        The code with google map link is nothing but just adding the latitude and longitude coordinates to the URL of the map page, so the link will take you directly to the google maps showing the corresponding location for the latitude and longitude values you just received.

    • admin says:

      The only change in code with a google map link is the lines to print maps URL. Just add the lines for URL under the comment in the code //The text of the message to be sent.

  75. Syed deep says:

    Please help me to sending SMS to multiple recipients , on this program
    How to sending SMS to multiple recipients ar same time

    • admin says:

      If you need to add an additional number, just repeat the code between lines “sgsm.print(“AT+CMGF=1\r”);” and “sgsm.write(0x1A);” with alternate number after the line “sgsm.write(0x1A);” in the current code.
      Or if you need to send to multiple numbers, save the numbers to an array, number[] = {“AT+CMGS=\”+ZZXXXXXXXXXX\”\r”,…,”AT+CMGS=\”+ZZXXXXXXXXYY\”\r”}
      then call number[0],number[1] using a for loop as sgsm.print(number[i]);.

  76. Syed deep says:

    After press switch , send message but not send location, only send 00000000.000000000 , location not send , wait i do sir

    • Syed deep says:

      And i check my GPS module, its working in demo code , and gate location in serial monitor, in this program gps not work, only send 000000 in sms,

      • admin says:

        You are getting the GPS location in separate GPS code but not in code with GSM, right. Try to print GPS code in serial while using the GSM code and check whether you are getting any GPS values.
        Can you share the exact code and circuit arrangement you have used?

  77. Aung myo htet says:

    I have not get latitude and longitude with google map.please explaun Sir

  78. syed mosharaf hossain says:

    how to make call and send massage on this code for 2 different number , and how to on auto reapply for send a massage in sim 800l and the sim800l also reapply a massage and location

  79. Aung myo htet says:

    Hi Sir. I have not get gogle map link with latitude and longitude in your second code.What wrong?please explain me .
    This is important for my project.please

  80. Syed deep says:

    Sir i need some help , in my code , my code is run complete, but i also need some changes, so sir please help me out , i add some extra features in my code

  81. Aung myo htet says:

    Early day that you send conding me are the same

    • admin says:

      Try changing the pin numbers currently, you are using with alternate pins like,
      SoftwareSerial sgps(10, 11); // RX, TX
      SoftwareSerial sgsm(12, 13); // RX, TX

      Try adding sgsm.listen() before sgsm.print(“\r”); and sgps.listen() before sgps.available() .

  82. syed mosharaf hossain says:

    its my code , i press a switch it send a sms, sir plz edit me the code, for make a call , when i press switch , the gsm module make call in this number
    void SendMessage1(){
    digitalWrite(Buzzer,LOW);
    mySerial.println(“AT+CMGF=1”); delay(1000); mySerial.println(“AT+CMGS=\”+919635838675\”\r”);
    mySerial.println(“PLZ HELP ME: “);
    mySerial.print(“LAT = “);
    mySerial.println(flat,6);
    mySerial.print(“LON = “);
    mySerial.println(flon,6);

    • admin says:

      Add the below code just after sms code or if sms is not required replace sms code.
      mySerial.println(“ATD+ZZXXXXXXXXXX;”);    //ZZXXXXXXXXXX – number
      delay(30000);
      mySerial.println(“ATH”);

  83. Syed mosharaf hossain says:

    Sir, the code above GSM and GPS, if you press a switch, the location will go. One thing I want to add to that CODE is what to do if someone calls GSM and the call is automatically received.

  84. Aung myo htet says:

    I try but do not get any message

  85. Raj says:

    Hi admin

    Am using neo 6m n sim800l v1 am getting SMS with no coordinates: latitude: 0.000000 longitude: 0.000000 plz help

  86. hamza says:

    Am using sim900d i need to add for another platform how i do

  87. Keerthana Sridhar says:

    Hello admin, How to use this data(locations) that we get and integrate it with cloud?
    I want to store this location in cloud.

  88. Brian says:

    hello sir,i have a problem when it comes to editing the code to add multiple numbers and receiving the coodinates in url format. Kindly help…. Thanks in advance

  89. Raphael Ofordum says:

    I wanted to ask I am using sim800l and neo 6m. Please I need the code for it. And also I want to ask for power supply recommendations. Please

  90. sandeep says:

    tnx bro expellant work very help full good joy bast of luck

  91. Raphael Ofordum says:

    Thank you for your answers. Please on your last answer I am using Arduino nano. So I am using the connection like I saw in the code to send gps to SMS please I need the complete code to send gps to SMS. Thank you in advance

    • admin says:

      You can use the same code in the above post. Both nano and Uno are using atmega328, so the pin numbers are the same and the same code works in both.

  92. HarisLatiff says:

    Hello sir, i am using arduino nano for this project, should i change the pin? and delete the switch code.
    I really need a coding for arduino nano interacting with gsm 900a to ask for gps .
    which pin is connected to the rx tx?

    • admin says:

      You can use the same pins as in the circuit. If the switch code is removed then it keeps sending the SMS repeatedly.

  93. morgana says:

    hi sir just copy and paste 3 coding from above?

  94. Samir Khan says:

    Sir can I use this program for Live location of my car

  95. muhd nur says:

    hai, if i want to use arduino mega, is it pin for gps amd gsm still same, if it different, what the coding??

  96. M.Rizwan says:

    Sir please help me for final year project we are using sim 800l Neo 6m GPS module with piezo vibration sensor and the microcontroller is esp 32 and our requirements is to send Sms to numbers and the android application through firebase so how we integrate these modules and how we code these modules please help us sir we have just few days to submit this project sir if you don’t mind please send me detail about that through email.

  97. Lily says:

    Admin how to send GPS Location Via telegram using GSM module and nodemcu, GPS module?

  98. Dev says:

    Arduino: 1.8.13 (Windows 10), Board: “Arduino Uno”

    Accident_Detector:2:10: fatal error: TinyGPS.h: No such file or directory

    #include

    ^~~~~~~~~~~

    compilation terminated.

    exit status 1

    TinyGPS.h: No such file or directory

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    That is error

  99. Karthik says:

    Can this program ran to nano? Is working or not

  100. Bibek says:

    Where is the library

  101. xddd says:

    hi sir is it possible to combine the gps and the sim5320e into the same module ?

  102. wee kang says:

    hi sir i am currently using a sim5320e and a gps can both this be combined to the same module as we want to minimize space if so what code should be change? do we need to be outdoors for the gps module to work? thx in advance

  103. dew says:

    I used a limit switch but it doesn’t work. what I need to do

  104. sultan mirza says:

    admin can we use this code for nodemcu esp8266 but i was havig sim808(gps+gsm) plz respond

  105. JJ POGI says:

    Sir, I test seperately both gsm and gps.
    gps has value on serial monitor and the led was blinking. And gsm module can send, receive sms and the signal is good. but if i run it together I can’t get any reply from the module. I also used a sufficient power supply for gsm module. Also it was perfectly work on switch press. But i was having a problem when it comes to sms request. What should I do Sir ? Thank you..

    • admin says:

      if that the case, print the string c in the serial monitor which is “String c = sgsm.readString();” and check whether you are properly receiving the SMS and it has a text “GET-GPS”.

      • JJ POGI says:

        Tried to read string c. but i havent seen any data on serial monitor.

        Serial.println(c);

        • admin says:

          That means you are not receiving the SMS.
          Try adding below two lines after sgsm.listen();,
          serial.println(“AT+CMGF=1\r”);  
          serial.println(“AT+CMGR=1\r”);//Read SMS at location 1.
          If the above two line not working try this lines instead,
          serial.println(“AT+CMGF=1\r”);
          serial.println(“AT+CNMI=2,2,0,0,0\r”);
          Refer: https://mechatrofice.com/arduino/gsm-send-sms (Receive SMS using GSM module) Try with the code only for receive SMS.

          • JJ POGI says:

            Sir i already do that, seperately and it can send “HELLO WORLD” like in the example, and i receive messages. by the way sir I use sim800L

          • JJ POGI says:

            sir after i add this code begore sgsm.listen()
            serial.println(“AT+CMGF=1\r”);
            serial.println(“AT+CMGR=1\r”);

            it is now sending gps location. but my problem now is it has no value
            lat. 00000000 long 0000000000
            my gps is working and the led is blinking. If i test it separate it has value in serial monitor.

          • JJ POGI says:

            I also try to change the connection. instead of software serial. I use the Rx-Tx connection of arduino to Gsm module. and it sends me the gps location with value. but the problem is it sends me gps location every 30secs without texting “GET-GPS

      • JJ POGI says:

        Sir I really need your help. i am working with it for the past 3 days. but still cant figure out where is the problem.

        • admin says:

          Use the same code used in the article to send SMS on request. But this time remove the GPS code completely and send some text.
          Just to check that whenever you send “GET-GPS ” the circuit can send any SMS.

  106. Shasha says:

    Hi sir, i also got 0 coordinates and on the serial monitor it also shows 0 but the gps module is blinking just fine. I tested it seperately and the gps gives coordinates on the serial monitor but when combined with gsm the coordinates just come up as 0. Any advice you can give to help me sir?

    • admin says:

      You have to troubleshoot by changing RX/TX pins, checking the power supply source – whether it can deliver power for both modules at a time, disabling separate parts of the code, etc.

  107. Sharon hazan says:

    what modules did you use fo the SMS/GPS?

  108. sofie says:

    hi sir, i have this project that requires arduino nano, gps, gsm, pulse sensor 433 MHZ RF Transmitter and Receiver and Battery. the system should make a buzzer sound once the button is pressed on and then send current location and current pulse rate to the registered number. the system is divided into two parts, the transmitter part: 433 MHz RF transmitter and SOS button, when button is pressed a buzzer sound will be generated in the receiver part which consist of 433 MHz RF receiver, arduino nano, gps, gsm and pulse sensor. the data will be sent from transmitter part to receiver wirelessly and allow to send current location and current pulse rate to the registered number. can you help me with the code or how to connect the circuit. thank you

    • admin says:

      Refer to the code: https://mechatrofice.com/arduino/rf-remote-controller-using-arduino-and-ask-module; Modify the code in this article by removing the part of data to “off”, so when the switch is pressed it sends a switch ON message.
      At the receiver part, under the action of switch ON use the above code in this article to get the GPS data and send it via GSM. Along with latitude and longitude, you can add sgsm.print(“Pulse”) or the data of pulse rate.

      • sofie says:

        thank you so much, but what do you mean by removing the part of data to “off” ?. Do you mean to remove the switch_off in the code ?

        • admin says:

          Yes, because you only need to repeat a single action.

          • sofie says:

            so for the Transmitter code should be like this right:

            #include
            #include

            const int switch_on = 2;
            int state = 0;
            char *msg;
            RH_ASK driver;

            void setup()
            {
            driver.init();
            pinMode(switch_on, INPUT);
            }

            void loop()
            {
            if (digitalRead(switch_on) == HIGH) {
            msg = “Switch_ON”;
            state = 1;
            }
            else if (state == 1) {
            driver.send((uint8_t *)msg, strlen(msg));
            driver.waitPacketSent();
            delay(200);
            state = 0;
            }
            }

          • admin says:

            Yes, but as swith off is not required, inside the void loop below code is enough,
            if (digitalRead(switch_on) == HIGH) {
            msg = “Switch_ON”;
            driver.send((uint8_t *)msg, strlen(msg));
            driver.waitPacketSent();
            delay(200);
            }

      • sofie says:

        do i need to use two Arduino. One with the transmitter part and the other one with the receiver part, or do i just use only one Arduino Nano in the receiver part ?
        because as the link you told me to refer to, it uses two Arduino. but the project i am working on only requires one Arduino in the receiver part . do you think i should add an Arduino in the transmitter part or not. I’m not sure, can you advise me i would appreciate it.

        • admin says:

          Yes, you need two Arduinos as per the given method. Because the transmitter and receiver need an Arduino to run the TX and RX sketch as it is using an ASK library. If need to do without Arduino then you can use the ASK itself without a library but the chance of error is high. Or you can use another module or a single channel RF remote.

      • Emerson Mina says:

        Hello, im using an SIM800L it is the same code for the SIM900?

        • admin says:

          Yes, it could work with this code, if you have any specific module look for the AT commands. Because the Arduino is communicating with the GSM modules by just using the AT commands.

  109. Stephen says:

    awesome, thanks.

  110. Nephian says:

    Do i need to remove the button to make the sms request function work ?

    • admin says:

      The code for SMS requests has nothing to read about the button input so it is not required and it has no effect on that circuit or code. But even if you leave with the button input as in the circuit it has no issue with working.

      • Nephian says:

        The Button Circuit and Code is perfectly working but if i try the sms receive code i dont even get an sms

        • admin says:

          Separately check the code to receive the SMS and make sure you are receiving the text “GET-GPS”; use the serial monitor to print the string.

  111. Fareed says:

    Sir how to use above code with haversine formula

  112. Hema says:

    Hi. We have uploaded the code . There were no errors but we are not getting any output .where is the mistake .Admin please help me .

  113. xenia says:

    Hi! I’m doing a project in which I want to connect a GPS locator to my phone, or build a device with an Arduino nano that remotely sends a signal from my location to a second device every time the button on device 2 is pressed. The second device It will be connected to an LCD screen and instead of reproducing the data of my location, that makes the conversion for example to: The subject is X meters from here (example that makes the calculation of how much is device 1 from device 2 and appears on the screen when you press the button). Its viable? What kind of software / tools would I have to use to create this connection remotely? Can the data be transformed so that it does the calculation that I have commented in the example? Thanks.

  114. tharun says:

    Hii admin, I’m doing a project on tracking the live location of passenger if an accident oocurs ..
    how can I implement in coding side and what components should i used ??
    please reply

  115. Ashfaq says:

    After press switch , send message but not send location, only send 00000000.000000000 , location not send , wait i do sir and i aslo check my GPS module, its working in demo code , and gate location in serial monitor, in this program gps not work, only send 000000 in sms.

  116. Hema says:

    Hi admin .I’m getting location but only 00.000000 is coming .Both gps and gsm are working fine individually .what should I do now

  117. Tushar says:

    Hi Admin,

    I’m making a project to make a autonomous RC plane. So far the plan is to include GSM/GPS module to my arduino with gryoscope/accelerometer sensor. Will be sending/receiving data to the arduino through GSM module to have a monitor over the flight behavior. Also will I be able manually override the plane i.e to control the wing movements of the plane thru by sending data to gsm module–>arduino–>actuators, what will be the delay impact?

    I will give a flight path coordinates and would be expecting the plane to follow the path using PID control.
    If you have any suggestions please let me know. Really excited to do this.

    • admin says:

      Sending data, you mean to use the GPRS of the GSM module? An RF control might be the better option.
      Yes, the RC can obtain the direction from the flight path coordinates and navigate with the help of a compass module.

      • Tushar says:

        Hi Admin,

        The plan is to control the plane using my phone through Blynk app. I think it would be better to use a NEO6M GPS module, with an esp32 wifi module. I not yet sure about the range of the WiFi module, but this is what I’ve improved with my idea so far. Please help me with more suggestions.

        Thank you!
        Tushar

        • admin says:

          I don’t think wifi is a good option for your application since it is an RC plane. Better go for RF modules with enough range like modules of Lora, XBee, NRF with antenna, etc.

          • Tushar says:

            ok sir, thank you so much!!
            also will I be able to interface the above modules like LoRa , NRF with my android phone in anyway ?

          • admin says:

            Yes, you will be able to interface similar modules with an android phone via a microcontroller connected through Bluetooth or wifi. But the performance and functional quality is hard to predict, it can be found only by testing the circuit as a whole.

  118. Shiragane says:

    Hi Admin, the code only works when I disable one of the module in the code seems I can’t use them simultaneously

    • admin says:

      Did you check the external power supply, that it has enough power to work with both modules simultaneously?

  119. mazuu says:

    Hi admin, i’m doing the project that have to send coordinates to a desktop system using GSM SIM800C, NEO 6M GPS MODULE and ATMEGA328, how can i make it,,, your help pls because i have tried different ways but the gps didn’t light up

    • admin says:

      If the GPS is not lighting up then it might due to poor signal, try it outdoor and try changing the position of the antenna.
      To send coordinates to a desktop system you can receive the SMS to an Arduino circuit connected with a GSM module, then the data can be read via the serial monitor, wifi, Bluetooth, or internet (if the GPS device has GPRS connectivity then the coordinates can be directly shared to the desktop via the internet without sending SMS).

  120. Khizar says:

    Hi admin. Please tell me name of gps module and controller name

  121. Shraddha Singh says:

    hey admin, can you please look at my code once. individually components are working but when I’m using them all together then no response. Here I’m using two ultrasonic sensor, rain sensor, buzzer, neo 6m, sim900a, switch button and arduino uno.
    Is arduino sufficient to power all components or I need to give external supply to some components. Thank you.

    #include
    #include
    SoftwareSerial gpsSerial(9,10);
    SoftwareSerial gsmSerial(7, 8);
    TinyGPS gps;

    int buttonPin = 11;
    const int buzzPin = 6, rain = A4;
    const int echoPin1 = 2, trigPin1 = 3;
    const int echoPin2 = 4, trigPin2 = 5;
    long duration1, duration2;
    int distance1, distance2;
    int state = 0;
    float lat, lng;

    void setup()
    {
    pinMode(trigPin1, OUTPUT);
    pinMode(echoPin1, INPUT);
    pinMode(trigPin2, OUTPUT);
    pinMode(echoPin2, INPUT);
    pinMode(buzzPin, OUTPUT);
    pinMode(rain, INPUT);
    digitalWrite(buzzPin, LOW);

    Serial.begin(9600);
    delay(100);
    gpsSerial.begin(9600);
    delay(100);
    gsmSerial.begin(9600);
    delay(100);
    Serial.println(“System is getting ready.”);
    }

    void loop()
    {
    distancecheck();
    buzzercheck();
    SendMessage();
    }

    void distancecheck()
    {
    digitalWrite(trigPin1, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin1, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin1, LOW);

    digitalWrite(trigPin2, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin2, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin2, LOW);

    duration1 = pulseIn(echoPin1, HIGH);
    distance1 = duration1 * 0.0175;
    duration2 = pulseIn(echoPin2, HIGH);
    distance2 = duration2 * 0.0175;

    Serial.println(“Distance1: “);
    Serial.println(distance1);
    Serial.println(“Distance2: “);
    Serial.println(distance2);
    }

    void buzzercheck()
    {
    if (distance1 <= 500 || distance2 <= 500 || digitalRead(rain) == HIGH)
    digitalWrite(buzzPin, HIGH);
    else
    digitalWrite(buzzPin, LOW);
    }

    void SendMessage()
    {
    gpsSerial.listen();
    while (gpsSerial.available())
    {
    int c = gpsSerial.read();
    if (gps.encode(c))
    gps.f_get_position(&lat, &lng);
    }

    if (digitalRead(buttonPin) == HIGH && state == 0)
    {
    Serial.println("BUTTON PRESSED");
    gsmSerial.listen();
    gsmSerial.print("\r");
    delay(1000);
    gsmSerial.println("AT+CMGF = 1\r");
    delay(1000);
    gsmSerial.println("AT+CMGS = \"+91xxxxxxxxxx\"\r");
    delay(1000);

    gsmSerial.println("IT'S AN EMERGENCY, NEED HELP. MY LOCATION IS: ");

    //https://maps.google.com/?q=12.905488,77.519113
    gsmSerial.print("https://maps.google.com/?q=&quot;);
    gsmSerial.print(lat, 6);
    gsmSerial.print(",");
    gsmSerial.println(lng, 6);
    delay(1000);

    gsmSerial.write(0x1A);
    delay(100);
    state = 1;
    }

    if (digitalRead(buttonPin) == LOW)
    state = 0;
    }

    • admin says:

      You need an external power supply, because modules like sim9000a GSM requires considerable amount of amperes. So use an external supply and provide a common GND connection.

  122. Anil says:

    Hi admin ,
    how to add Ultrasonic sensor to this project , i just want give buzzer info after the object detected , can u please include the ultrasonic sensor code and send

    thanks a lot ..

  123. pooja says:

    SIR IM GETTING MY LOACTION AS 0,0 WHAT IS THE MISTAKE

  124. Vamsi says:

    Admin sir if you don’t mine can you please send the code with the replace of switch with 433 MHZ Transmitter ND reciever with RF IC boards and the output from RF RECIVER is connected to ARUDINO uno and which it is connected to GPS module and GSm module. When button is rf Ic board(transmitter) .there is signal transmitted to rf Ic board(reciver) which is connected with help of jumper wire from RECIVER to arduino uno which get location and transmitted to phone number using GSM module. Pls sir Pls sir waiting eagerly for your reply.. Thank you sir for this opportunity.

  125. Vamsi says:

    Hi admin. I am getting location as 0,0 .can you please let me know what the issue .pls solve this issue.

  126. hfa says:

    can i use this code with dragino lora shield too? if i can, can you tell me what part i suppose to edit? pls reply, thanks admin

    • admin says:

      If you have to add Lora with this project you have to include the additional library for Lora and need to add its functions in the code as a whole.

  127. jazz says:

    hi admin, thanks for the tutorial. but i have the problem. i don’t get the reply from the module gsm. im using arduino uno, sim900a, and dragino shield lora. i have the project about lora. module gps work with the lora (another device) and send the location to module gsm with lora device too. but i don’t get the reply from module gsm. please help, many thanks

  128. jiminie says:

    Hi sr, could it be possible for it to be triggered both in the switch, and sending sms request for gps location but only in one arduino? or do I need separate arduino for the both to function?

    • admin says:

      You can do both switch triggering and sending SMS with a single Arduino.

      • Ninshow says:

        Can you show how? Thank you

        • admin says:

          The code for GPS receiver and sending SMS is the same in both codes the only difference is the triggering. So by just adding two separate conditions to check, both types of triggering can be used.

        • admin says:

          Try the below code, here the code to send SMS is defined as a function with name sendsms(). Then it can be called for both separate triggerings; switch and sms request.

          void loop(){
          sgps.listen();
            while (sgps.available())
            {
              int c = sgps.read();
              if (gps.encode(c))
              {
                gps.f_get_position(&gpslat, &gpslon);
              }
            }
          // if condition to check switch press
           if (digitalRead(pin) == HIGH && state == 0) {
          sendsms(); // call function if push switch is pressed.
          state = 1;
              }
          if (digitalRead(pin) == LOW) {
                state = 0;
              }
          
          // if condition to check SMS request
          sgsm.listen();
              if (sgsm.available() > 0) {
                String    c = sgsm.readString();
                c.trim();
                if (c.indexOf("GET-GPS") >= 0) {
          sendsms(); // call function if SMS request is true.
          }
          }
          
          
          //Add code to send SMS as a function. 
           void sendsms() {
             sgsm.listen();
                sgsm.print("\r");
                delay(1000);
                sgsm.print("AT+CMGF=1\r");
                delay(1000);
                /*Replace XXXXXXXXXX to 10 digit mobile number &
                  ZZ to 2 digit country code*/
                sgsm.print("AT+CMGS=\"+ZZXXXXXXXXXX\"\r");
                delay(1000);
                //The text of the message to be sent.
                sgsm.print("Latitude :");
                sgsm.println(gpslat, 6);
                sgsm.print("Longitude:");
                sgsm.println(gpslon, 6);
                delay(1000);
                sgsm.write(0x1A);
                delay(1000);
          }
          
  129. finalproject says:

    https://www.google.com/maps/?q=27.988139,86.924974 <— this works when I used Maps for Browser but when I used Google Maps Apps(Android), it doesn't appear anything. What's the solution?

  130. Saniya says:

    Hi admin, can I use other modules for this like the sim900?

  131. danica says:

    good day sir. in the gps there is 5v may i ask where it is suppose to connect and what “if condition” should be remove. is it the last part of the code or the in the upper part of the code where that code is if (gps.encode(c))
    {
    gps.f_get_position(&gpslat, &gpslon);
    }
    }
    if (digitalRead(pin) == HIGH && state == 0) {
    sgsm.listen();
    sgsm.print(“\r”);
    delay(1000);
    sgsm.print(“AT+CMGF=1\r”);
    delay(1000);

    hope you answer 🙂

    • admin says:

      Connect to a power source of +5V with the GND connected in common. The if condition to alter the triggering is the last one that is “if (digitalRead(pin) == HIGH && state == 0)”.

  132. Erik A. says:

    Hi, when sending Google Maps coordinates as follows:
    [code]
    sgps.print(“http://maps.google.com/maps?q=”);
    sgps.println(gpslat);
    sgps.print(‘,’);
    sgps.println(gpslon);
    [/code]
    then an sms is received with url as follows:
    https://maps.google.com/maps?q=51.201694 but the longitude appears outside the url link: first a comma then the longitude.
    How can the longitude be made part of the url link?
    Thanks a lot!
    Erik

    • admin says:

      Check for any space or hidden characters between the text, if any try removing them.

      • Erik A. says:

        Solved: your Google Maps command should be changed to

        sgps.print(“https://www.google.com/maps/search/?api=1&query=”);
        sgps.print(gpslat, 6);
        sgps.print(‘,’);
        sgps.print(gpslon, 6);

  133. XiaozzZZ says:

    Hi, can you please help me admin, my gps just sends 0.000000 latitude and longitude locations. I already checked that the gps is working fine with other codes.

  134. Maanyat Periwal says:

    Will it work with SIM 800L

  135. Maanyat Periwal says:

    The same code ??

  136. Rahul says:

    Hello sir can I use sim800A & is it work with same code?

  137. john says:

    hey admin.. what if i used ultrasonic sensor as trigger to send gps coordinates using gsm simm800L

  138. faiz says:

    hiii sir, Vcc of GPS module should be connected to 5v power supply? and please give me the link to check whether GPS and GSM interfaced with Arduino Uno are working individually or not?

  139. gablin says:

    I’m using Sim800L EVB is this works fine or not? and if you have source code for using sim800L evb can you kindly send a link much appreciate

  140. Nisarg patel says:

    Hello sir, We are using MQ-3 sensor for detecting alcohol in our project. So we want to connect sensor to this circuit. So I want to know that which changes we have to do in circuit and code ?

    • admin says:

      Replace the “if condition” to check the switch press with the sensor output, so as to compare the threshold value for analog input or a boolean logic to detect the HIGH or LOW state for digital input.
      Replace the push button pin with the MQ-3 sensor output.

  141. shanmugam says:

    Hi admin i am using gsm gprs sim800a 4g LTE module all are fine but not sending sms in the module please tell me what is the problem and send me the code for any different for SIM800A module

    • admin says:

      There could be several reasons why the SIM800A module is not sending SMS messages. Some common issues include:

      Incorrect configuration of the module: Make sure that you have configured the module properly with the correct APN, PIN, and other settings.

      Insufficient balance or credit on the SIM card: Make sure that you have sufficient balance or credit on the SIM card to send SMS messages.

      SIM card not activated or blocked: If the SIM card is not activated or has been blocked, it will not be able to send SMS messages.

      Incorrect AT commands: Make sure that you are using the correct AT commands to send SMS messages with the SIM800A module.

      Try this sample code to send SMS using the SIM800A module and make sure the SMS sending is working fine:

      #include SoftwareSerial.h // include the SoftwareSerial library
      
      SoftwareSerial SIM800A(7, 8); // create a SoftwareSerial object to communicate with the SIM800A module
      
      void setup() {
      SIM800A.begin(9600); // start the SIM800A serial communication at 9600 baud rate
      sendSMS(); // call the sendSMS function
      }
      
      void loop() {
      // loop function is empty
      }
      
      void sendSMS() {
      SIM800A.println("AT+CMGF=1"); // set the SMS mode to text
      delay(1000);
      SIM800A.println("AT+CMGS="+1234567890""); // set the destination phone number
      delay(1000);
      SIM800A.println("This is a test SMS message."); // set the SMS message
      SIM800A.println((char)26); // send the SMS message
      delay(1000);
      }

      Note: Make sure to replace the destination phone number with the actual phone number that you want to send the SMS to. You may also need to adjust the delay times based on your specific setup.

  142. Moiz says:

    Hii Admin
    If i want to add a fingerprint to it how can i do that .Like instead of push button on every fingerprint sense a message has to be send.will you plzz help me with this

    • admin says:

      In the same arrangement only thing you have to replace is the “if” condition that checks the push button state, replace it with a fingerprint to verify state is TRUE or FALSE.

  143. Harris says:

    Hi admin, when I pressed the button I only receive 0.000000 in both lat and lon in sms not my actual location, I already test my gps neo6m and my coordinates reflected in the serial monitor but when I use your code above I only get 0.0000000, is there any solution for this? thank a lot admin

  144. AKEI says:

    Bonjour, comment fusionner les deux codes svp?

  145. sai says:

    i have done his iam getting location that i have mentioned …. when i pressed the button i am getting location but same mobile location is sending via msg to same mobile

Leave a Reply

Your email address will not be published. Required fields are marked *