Arduino, GPS, and SMS: Texting GPS Coordinates

I started playing around with this GPRS shield that I recently purchased from Amazon for a mere $30:

The MFG’s website is here

http://www.geeetech.com/gprsgsm-sim900-shield-board-arduino-compatible-p-610.html

and the WIKI for the device is here:

http://www.geeetech.com/wiki/index.php/Arduino_GPRS_Shield

Some other good reference sites I found are:

http://www.cooking-hacks.com/documentation/tutorials/arduino-gprs-gsm-quadband-sim900

http://tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/

After I received it, I ordered a GSM SIM card from my cellular carrier (I don’t know how this works with a CDMA carrier like Verizon – my guess is it doesn’t). The GPRS shield is just another handset on my wireless plan and uses the same shared voice/text/data.  I simply plugged in the new SIM card and it worked on the first try.

I attached the GSM/GPRS shield to an Arduino Uno and wired the ublox GPS ontop of that using a breadboard shield. The wiring diagram is:

gsmgpsdemo-fig2

(Feb 2016 update: going back to set the GPRS field up again but put it on a Mega – the shield does not work directly connected to a Mega because the softwareSerial doesn’t support pins 7&8 on the Mega. To use the mega, you cannot directly connect the shield onto the mega).

The first thing I did was setup a test sketch like this that lets you type AT commands into the GPRS shield thru the arduino:

http://www.geeetech.com/wiki/index.php/Arduino_GPRS_Shield#Step_1:_Creating_a_test_setup_for_the_GPRS_Shield

I was then able to determine I had connectivity with the shield.

Then I found the AT command set for the SIM900 chip that is used:

http://elecfreaks.com/store/download/datasheet/rf/SIM900/SIM900_AT%20Command%20Manual_V1.03.pdf

I went thru the manual and figured out some of the commands that I would want to use such as

send text

at+cmgs="8005551212"
> this is a test
> ctl-d
get all waiting texts

at+cmgl="ALL"
+CMGL: 1,"REC UNREAD","18005551212","","15/03/06,22:25:53-32"
Test reply
delete all msgs: 

at+cmgda="DEL ALL"
OK

Once I was sure I could send/list/receive/delete SMS messages, I was ready to get the GPS running.

I implemented the TinyGPSPlus library as I had earlier in Connecting u-blox NEO-6M GPS to Arduino. But I was seeing a lot of checksum errors and further research into that indicated I was having way too many buffer overflows. The GPS’s default baud rate of 9600 baud was too fast for the TinyGPSPlus library to decode so I had to change the baud rate to 4800 baud as outlined here: High Checksum Errors with u-blox NEO-6M GPS and Arduino.

I am using the SoftwareSerial library to communicate with both the GPS and the GPRS. It turns out that this library will not allow you to listen to both devices at the same time. You must indicate which device you want to listen to with the xxx.listen() method.

Most of the time, my code will be listening to the GPS and decoding the serial stream coming from the GPS. This is done by calling gps.listen(). When I’m ready to check for SMS messages, I then use gprs.listen(). This works reasonably well. I do get some checksum errors because of incomplete GPS messages, and if I wait too long before reading the GPS again, the locational data can get stale (especially if the GPS were in a car moving fast).

Once I had this figured out, I fleshed out the code to listen for ANY SMS message. I don’t try to determine what the message may say, I just assume if my GPS/GPRS is getting a message, I need to respond with the location. So I format a text message as a google maps URL, and transmit it to a fixed phone # (this is, after all, just a demonstration program).

The final result worked quite nicely. I send the arduino a text message, and get back a URL of its location. Here is a google voice log of a message to the Arduino, and its response:

gsmGpsDemo-fig1

The source to my demo program is available here.

I use code::blocks as my IDE most of the time rather than the Arduino IDE, so you will see somethings you might not see in the Arduino IDE, such as having to define forward references to all of my functions. However, it will compile fine in the Arduino IDE.

 

Advertisements
This entry was posted in c-arduino and tagged , , . Bookmark the permalink.

27 Responses to Arduino, GPS, and SMS: Texting GPS Coordinates

  1. Pingback: Arduino, GPS, GSM/GPRS: Transmitting GPS Coordinates via UDP to Google Maps | Big Dan the Blogging Man

  2. peter says:

    hi there i love your project and i am working on the same thing, the problem is i tried using your demo code to see if it works, and it does if i send ‘T” from the serial monitor. BUt the problem is that when i try to text it from my cell, i get no response, any way you could help me out? thank you

    im using an arduino uno
    GPRS/GSM sim900 V3 shield (SeeedStudio)
    Adafruit gps

    i changed the baud rates and it communicates via serial monitor but not when i send it a text. thank you for all your help in advance.

    • Dan TheMan says:

      It’s been 6 months since I touched this and haven’t thought about it since, so I remember only what I wrote down.

      Unfortunately, from your description, I don’t have a clue where the problem may lie. Is the GSM module receiving the text , the the arduino getting the response, is the arduino sending the text? There are a lot of possible points of failure.

      My only suggestion is that you put Serial.println’s into the code to figure out where the problem is occurring. If you can isolate the problem to a chunk of code and can’t figure out why that chunk of code isn’t working, I might be able to look at the errant code and give you some ideas.

  3. Harzel says:

    Hi sir, I’m a student trying to learn about arduino and GSM/GPRS/GPS shield combination. I really need to have a working code for this project. I need your knowledge about this. I intend to build a tracking device that can send GPS coordinates location via SMS to a designated mobile number, I already tried to look at your demo code but I can’t find the right code to manipulate google maps and to finally send the exact coordinate where the arduino is. I really need your help. Thanks and Godbless.

  4. Harzel says:

    Hi sir, I’m a student trying to learn about arduino and GSM/GPRS/GPS shield combination. I really need to have a working code for this project. I need your knowledge about this. I intend to build a tracking device that can send GPS coordinates location via SMS to a designated mobile number, I already tried to look at your demo code but I can’t find the right code to manipulate google maps and to finally send the exact coordinate where the arduino is. I really need your help. Thanks and Godbless.

    • Dan TheMan says:

      This blog post only covers xmitting coords over GSM to an SMS device. Take a look at my other post here

      https://bigdanzblog.wordpress.com/2015/03/31/arduino-gps-gsmgprs-transmitting-gps-coordinates-via-udp-to-google-maps/

      which covers transmitting the coordinates to a Raspberry Pi via UDP. The RPI then deals with the Google Maps interface.

      I haven’t played with this stuff since last March so it has pretty much been cleared from my memory. I’m not going to be of much more help than what you will find on the link above. Look there and to the posts it refers and that should be enough to at least get you going.

      • Harzel says:

        Thankyou so much! Do you have any backup files from the march project you have done? I will read the link you gave me. Thank you so much!

      • Dan TheMan says:

        All of the code I used to do the two experiments in those two blog posts are documented in the posts. Some people (I believe with using Macs, but I’m not 100% sure) have found the examples in my post to be missing characters. If you see that, install an ad blocker. Evidently some ad software wordpress.com is using can cause issues.

      • Harzel says:

        And I only have Arduino Uno R3 and GSM/GPRS/GPS Shield with sim808 module. Can this work with my current modules?

      • Harzel says:

        Can i just use a mobile device rather than a raspberry pi? Or is it really necessary to have the module? Because all i really want is for the Arduino+Shield to send me the coordinates where it was hidden.

      • Dan TheMan says:

        You will have to look at how the code works. I cannot tell you how easily it would be to bypass the arduino. It may well be impossible because the RPI was being used to format the coordinates as Google maps requires. I barely recall the entire process was rather involved.

  5. kemi says:

    Hello, thank you for this, I have learnt a lot from this tutorial. A quick question though, is it possible to get the GSM to send the gps coordinates without having to send the ‘T’ or send the message to the GSM. I tried to take out the part where it waits for the user to input T, however I ended up getting 0s as the coordinates.

    • Dan TheMan says:

      Looking at the code, I use ‘T’ input to control when texts get sent since I don’t want a zillion texts being sent to me.

      It sounds like what you want to do is send a text of the coordinates every so often, let’s say once a minute. In that case, instead of waiting for the user to press a key you could just set a delay. I would change the main while loop to something like:

      while (true) {

      doGpsIo(); // decode next GPS character

      if (millis() > timeout) { // ever secs, check for SMS
      ssGprs.listen(); // start listening to GPRS
      doSmsMsg(); // check for incoming SMS and respond w/ coordinates
      ssGps.listen(); // go back to listening to GPS
      timeout = millis() + textScanTimeout * 1000UL; // determine next time to check for SMS
      }

      } // main while

      Note this is NOT tested code, I’m just throwing it out there for you. For example doSmsMsg probably needs to be changed to simply xmit the coordinates rather than see if someone is asking for the coordinates.

  6. Jason Losito says:

    Hi Dan,

    I am just starting out on Arduino and GSM/GPS modules so please bear with me.

    What if I want to send different replies depending on the sms that was sent to the arduino? How Can I do that?

    • Dan TheMan says:

      Hi Jason,

      When I wrote this, I guess I didn’t want to spend the additional time decoding messages since I knew I was always going to do the same thing.

      Because you want to do different actions based on the incoming text, you are going to need to extract the incoming text message. I don’t have any code on my blog talking about this though I have done it in a fairly large project.

      I get a list of messages using:
      mdmTx(“AT+CMGL=\”ALL\”,0″);

      I then parse all incoming messages and build an array of everything waiting. I go thru that array and process each message as required. Once done, I then delete every message I processed.

      Just a heads up: in the USA, AT&T has turned off (or is turning off) their 2GL network. The SIM800 is a 2GL device. Mine stopped functioning in early January.

      It sounds like T Mobile will continue to support their network a while longer.

      • Jason Losito says:

        Thank you for your very quick response! I am using an Elecrow SIM808. Your demo actually worked when I tried it. I am from the Philippines, by the way. 🙂 Just to share it with you, I building an Android/Arduino tracking device. I don’t have any issues on the Android side. You answer to my question is very clear, but I am still having difficulties understanding it. Maybe because I just started out with arduino. 🙂

        I only have two actions to process actually. 1) Reply “OK” when the device receive an SMS with the “token” for registering. This for the android app to register the device. 2) Reply with the latitude and longitude readings when the message has a token for asking the gps coords. That’s it.

        I can read the arduino sketch by I am still a beginner so I really do not know how to go about it. I hope you can help me…

    • Dan TheMan says:

      Since you are just starting out, you are going to want to try and find an example of someone else reading the SMS messages from the SIM800. I know I don’t have any examples. The following blog looks somewhat useful and they show how to use AT commands to experiment w/ the SIM800. There is also an arudino library for using at SIM800. I’ve never used it, but it may help make access easier for you

      http://www.ayomaonline.com/programming/quickstart-sim800-sim800l-with-arduino/

    • ken says:

      Hi jason, I’m also using elecrow sim808 same as yours but this code doesn’t work well with mine, did you also use arduino uno as your MC? if so, what modifications did you do with this code?

  7. khyra says:

    hi,
    i want to ask for your favor. i got a problem to get an url from latitude and longitude given. can you help me by telling what is the code for get an url to link to google maps. im using Arduino IDE. thanks

  8. Rajesh says:

    Hi Dan,

    Just curious to know one thing (may be I am missing something here)… I suppose SIM900 also provides location using AT+CIPGSMLOC=1,1 command (Pl see http://simcom.ee/documents/SIM900/SIM900_GSM%20Location%20AT%20Command%20Manual_V1.00.pdf for further details)

    My question is if SIM900 can provide the location details do we still need another GPS module like how it has been depicted in your example above?

    Many thanks.

    Regards
    Rajesh

    • Dan TheMan says:

      I am pretty sure the SIM900 does not support GPS. It appears only the SIM908 does that (per https://www.open-electronics.org/how-to-use-gps-functions-with-gsmgprs-gps-shield/). I’m not in a position where I can easily test the SIM900 I have, so you should check into this yourself. If it does, you certainly don’t need a separate GPS module. If you find the SIM900 supports GPS, let me know – I’d be interested.

      Also, in the US very few providers are still supporting 2G networks so the SIM900 is not a good choice for any new projects (unless there is a 3G update for it).

      This caused me issues at the beginning of the year. I had a device using a SIM900 in the field and AT&T turned off 2G. My unit was dead until I was able to find a T-Mobile 2G card and fix everything to use that.

      • Rajesh says:

        Thanks for your quick turnaround, Dan. After I did some reading I noticed that SIM900 only provides GSM location and not GPS.
        Appreciate your other informative comments.

        Regards
        Rajesh

  9. kevin says:

    hi dan,

    I’m am just starting out with arduino and gsm/gps modules so please bear with me. I am currently using elecrow sim808 shield with arduino uno. I tried using your code and it works fine but my gsm/gps shield’s gps function seems to be not working with this code. Can you please help me fix this? i really dont know what’s wrong with it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s