Introduction: Arduino GSM Shield 2

About: Electrical Engineer

This Journey can take you a head toward the wireless communication and the automatic control techniques that may help you start your great projects. It also can provide you with some important commands and processes that everyone can follow and apply then eventually be a creative one.

At the first, I going to explains some important AT command that Arduino Libraries used such as the great GSM library. You may wonder why to understand the AT Command while there is a helpful and great library can every used.

So Why AT command ?!.

I can say that there is a great library and easy to use, but we can't ignore the size of a program while including more than one library in one multi functions great program. The great program can become not stable and heavy in hex file result in poor in performance and mistakes could occurred while operating that great program.

On the other hand, AT command is much lighter, faster, and Errors can be easily detect beside a general purpose famous ("Software Serial Library")that can combine with other libraries in more efficient way. The only challenge is to be considering how much delay time each Command need to execute probably. This all information can be found in the Quectel M10 Data sheet.

Quectel M10 At command file is the only document you need in order to start write your own program for your great project. I`m highly recommend you going through the PDF file, Its has such a valuable information I hope you like.

If you understand what going on here, I expect you to have the ability to make a smart home,some security and safety applications, real time monitoring systems, wireless control systems. And you may create your cool project that I did not think about. Please make cool things and share them so we can learned more.

In this Journey I will cover the Arduino GSM shield in this Five Areas:

  1. Controlling applications via Sending SMS and Receiving as well.
  2. Making voice calling and /or sending SMS for Security applications.
  3. Making TCP web client over GPRS data [Realtime data logging].
  4. Making a real-time GPS tracking via SMS.
  5. Making a real-time GPS Tracker over the internet and Display GPS data on Google Maps.

Also, I will provide you by a quick guide for getting a free API`s key that I used to accomplish and test the Arduino GSM Shield which you can also get and use for your project for free.

Step 1: Components Required

_Hardware_

_ Software_

_Libraries required_

Step 2: The Arduino GSM Shield !! (Overview)

Description

The Arduino GSM Shield allows an Arduino board to connect to the internet, make/receive voice calls and send/receive SMS messages. The shield uses a radio modem M10 by Quectel (datasheet). It is possible to communicate with the board using AT commands. The GSM library has a large number of methods for communication with the shield. The shield uses digital pins 2 and 3 for software serial communication with the M10. Pin 2 is connected to the M10’s TX pin and pin 3 to its RX pin. See these notes for working with an Arduino Mega, Mega ADK, or Leonardo. The modem's PWRKEY pin is connected to Arduino pin 7. The M10 is a Quad-band GSM/GPRS modem that works at frequencies GSM850MHz, GSM900MHz, DCS1800MHz and PCS1900MHz. It supports TCP/UDP and HTTP protocols through a GPRS connection. GPRS data downlink and uplink transfer speed maximum is 85.6 kbps. To interface with the cellular network, the board requires a SIM card provided by a network operator. See the getting started page for additional information on SIM usage. The most recent revision of the board uses the 1.0 pinout on rev 3 of the Arduino Uno board.

Power requirements

It is recommended that the board be powered with an external power supply that can provide between 700mA and 1000mA. Powering an Arduino and the GSM shield from a USB connection is not recommended, as USB cannot provide the required current for when the modem is in heavy use. The modem can pull up to 2A of current at peak usage, which can occur during data transmission. This current is provided through the large orange capacitor on the board's surface.

On board indicators

The shield contains a number of status LEDs:

  • On: shows the Shield gets power.
    • Net: blinks when the modem is communicating with the radio network.
      • Status: turns on to when the modem is powered, and data is being transferred to/from the GSM/GPRS network.

For more Information see Getting Started with the Arduino GSM Shield

Also you can see GSM library.

The datasheet for the Quectel M10 modem can be found here

Step 3: Getting Started!

We will use two methods:

  1. The Terminal Emulator. (brief introduction see pics)
  2. Using Arduino code (Uno/Mega) compatible.

Now we will prepare the Arduino board for communicating with the PC by UART protocol. Emulate a second serial port (UART) using software on the digital pins D2 and D3 and patch through all the communication between this second software serial port and the actual hardware serial port. By doing this, all the data coming from the computer (connected to the actual hardware UART) would be relayed as is to the GPRS Shield (connected to software UART).

Now all done to start use Arduino with either method.

1. Using AT commands Via

  • Open your favorite serial terminal software, choose the COM port for Arduino and press connect.
  • Press and hold the power button a short while (Over 3 seconds) on the GMS Shield to turn it on.
  • Now, type and send "AT" (without the quotes) followed by carriage return (enter key) to the Arduino board. The GPRS Shield should respond by sending back an "OK". This would mean that you have been able to successfully setup your GPRS Shield can now play around with various AT Commands.

Sending a text message (SMS) –AT COMMAND

  • Install GSM shield in Arduino board and connect power cord.
  • Open your serial monitor program (I use SSCOM)
  • Through your serial terminal software, send AT+CMGF=1 and press the Enter key. The GPRS Shield can send SMSes in two modes: Text mode and PDU (or binary) mode. Since we want to send out a human readable message, we will select the text mode. The GPRS Shield will respond with an OK.
  • Send AT+CMGS="+966XX6541231" and press the Enter key (include the quotes). This will instruct the GPRS Shield to start accepting text for a new message meant for the phone number specified (replace the number with the phone number of the target phone). The GPRS Shield will send a > signaling you to start typing the message at the last of the massage type "*" (without the quotes).

Make a Call –AT COMMAND

  • Type ATD 0566996070; // Write phone number you want to call
  • Respond OK, you will receive a call.
  • Type ATH to end a call.

Step 4: Creating Thingspeak Channel for Storing GPS Data Received From GSM Shield And/or Monitoring Things

I assume that you already have a thingspeak account. If not then visit and create your account. Then, follow the below process:

  • Got to"Channels" and click on "New Channel" as shown in the image1.
  • Then Enter following details as shown in the image2.
  • Scroll down and hit "Save Channel" as shown in the image3.
  • Now your channel has been successfully created. Click on your created channel and then click on "API Keys" tab and you will get the following details: as shown in the image4.
  1. Channel ID
  2. Write API Key
  3. Read API Key

Which will be used by us for writing, reading the data on/from thingspeak server. So copy and pasted it on a notepad file and keep it ready.

See my Channel HERE

Step 5: Getting the Google Maps API Key !!

Preview

In this Step, we are going to get the json data from the thingspeak server and parse it using HMTL and javascript to show it in Google Maps along with a marker. I hope that you already have a google or gmail account. Follow the below steps to get the Google Maps API key which will be used in our code to get the json data and show it in the marker on Google Maps.

  • Go to HERE and click on "Get A Key" on the top right corner as shown in the below image.
  • Now Click on "Select or Create Project" in the dialog box which appears after clicking on "Get A Key" as shown in image1.
  • Select the "Create a new project" from the list as shown in image2.
  • Give a name to your project and click on "Enable API"as shown in image3.
  • Now you will get an API Key in a text box. Click on "copy clipboard" icon (the file on file icon) and hit "Finish". You now have Google Maps API key which you can use in your HTML code to show map.as shown in image.
  • Now copy and paste the following file in notepad++ and save it as "index.html".

See The File HERE

  • Now replace the following credentials: as shown in image5.
    1. Your Google API key
    2. Your Thingspeak Read API key
    3. Your Thingspeak Read API Key
    4. Your Thingspeak Channel ID
    5. Your Thingspeak Channel ID

Step 6: Connecting and Wiring

  • GPS tx/rx to the arduino digital pins 8/9
  • The devices to control to the arduino digital pins 8 to 12
  • The push bottom connect the arduino digital pin 4
  • The Temperature sensor data pin to the arduino digital pin 6

They all subject to change as you want, but you must change also in the arduino sketches as well.


For the power supply you can see the solar cell class lesson 4 to make your solar system.

Or simply use a 9 Volt AC adapter.

Step 7: SMS Control With Replay Codes

Controlling over SMS is a cool thing. I`m Showing this process for remote control things like on/off high power application such as a water pump at a farms or air conditioners at homes. You can simply play with these applications from any distance and any where as the network is available. Replaying for SMS is very important so you will able to determine that the air conditioner for example had work or not yet.

The key is a high power relays is placed that can micro-controllers can handle for the purpose of turning on off these devices. for example an air conditioner operate at 230 Volts and between 5 - 15 Amperes but a 20 Amperes Relay may not suitable. thats because started current may goes above 20 Amps that may cause a serious damages. you need to know all specification for the target device before you start you project. Safety is always First.


Lets begin taking a look on coding!!


<p>/*<br>  Commands
  SEND "#LEDo"   // GREEN  ON // (without the quotes).
  SEND "#LEDc"   // GREEN  OFF // (without the quotes).
  SEND "#BULBo"  // PUMP  ON // (without the quotes).
  SEND "#BULBc"  // PUMP  OFF // (without the quotes).
  SEND "#REDo"   // RED  ON  // (without the quotes).
  SEND "#REDc"   // RED  OFF // (without the quotes).
  SEND "#ALIo"   // ALI  ON  // (without the quotes).
  SEND "#ALIc"   // ALI  OFF // (without the quotes).
  SEND "#SETo"   // SET  ON  // (without the quotes).
  SEND "#SETc"   // SET  OFF // (without the quotes).
*/</p>


<p>// software serial #1: RX = digital pin 2, TX = digital pin 3<br>#include 
SoftwareSerial GPRS(2, 3); // RX, TX
#define LED 12
#define PUMP 11
#define RED 10
#define ALI 9
#define SET 8
String text = "";
char coming;</p><p>void setup() {
  // Initialize pins
  pinMode(LED, OUTPUT);    // make the LED pin output
  pinMode(PUMP, OUTPUT);   // make the PUMP pin output
  pinMode(RED, OUTPUT);    // make the RED pin output
  pinMode(ALI, OUTPUT);    // make the ALI pin output
  pinMode(SET, OUTPUT);    // make the SET pin output
  digitalWrite(LED, LOW);  // write LOW To the LED pin make it low as defult
  digitalWrite(PUMP, LOW); // write LOW To the PUMP pin make it low as defult
  digitalWrite(RED, LOW);   // write LOW To the RED pin make it low as defult
  digitalWrite(ALI, LOW);   // write LOW To the ALI pin make it low as defult
  digitalWrite(SET, LOW);   // write LOW To the SET pin make it low as defult
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  delay(3000);
  digitalWrite(7, LOW);
  GPRS.begin(19200);           // Start software serial
  delay(2000);
  GPRS.println("AT+CMGF=1");    // AT+CMGF Select SMS Massage Format
  delay(100);
  GPRS.println("AT+CNMI=1,2,0,0,0"); // AT+CNMI New SMS Massage INdication
  delay(100);
  GPRS.println("AT+CMGD=1,4"); // AT+CMGD=1,4 Range of SMS on SIM card Can be deleted
  delay(1000);
  SMSsend("SYSTEM IS TURN ON");// Start Massage To Make Sure The System Work
  GPRS.flush(); // deleting all massages at the first boot
  delay(100);
}</p>


<p>void loop() { // again and again forever<br>  sms();
  delay(1);
}</p>


<p>void SMSsend(String massage) {<br>  GPRS.print("AT+CMGF=1\r");                  //  Carriage return
  delay(100);
  GPRS.println("AT+CMGS=\"+966566996070\""); // replace x by your number ("AT+CMGS=\"+966xxxxxxxxx\""); to yours
  delay(100);                               // (+966) is the country code replace it with yours
  GPRS.println(massage);
  delay(100);
  GPRS.println((char)26);                    //the message stopping character
  delay(100);
  GPRS.println();
  delay(100);
  GPRS.println("AT+CMGD=1,4");              // some AT Commands
  delay(100);
  GPRS.println("AT+CMGF=1");
  delay(100);
  GPRS.println("AT+CNMI=1,2,0,0,0");
  delay(200);
  text = "";
}</p><p>void sms() {<br>  while (GPRS.available()) {           // Delay time in between to improve stability
    delay(3);
    coming = GPRS.read();
    if (coming == '#') {               //SMS commands must begins with # otherwise messages will be ignored And Then Deleted At The Next Boot
      if (GPRS.available()) {
        delay(3);
        coming = GPRS.read();
        if (coming == 'L') {           // read serial
          if (GPRS.available()) {
            delay(3);
            coming = GPRS.read();
            if (coming == 'E') {        // still reading the serial
              if (GPRS.available()) {
                delay(3);
                coming = GPRS.read();
                if (coming == 'D') {    // still reading the serial
                  if (GPRS.available()) {
                    delay(3);
                    coming = GPRS.read();
                    if (coming == 'o') {
                      digitalWrite(LED, HIGH);     // write HIGH to the LED pin  when The Recieved massage is MATCHED
                      SMSsend("GREEN LED ON");     // sending the massage  to the user mobile tO make sure command is recieved and  successfully executed
                    }
                    else if (coming == 'c') {
                      digitalWrite(LED, LOW);      // write LOW to the LED pin  when The Recieved massage is MATCHED
                      SMSsend("GREEN LED OFF");    // sending the massage AFTER commands successfully executed
                    }
                  }
                }
              }
            }
          }
        }
        else if (coming == 'P') {         // Delay time in between to improve stability
          if (GPRS.available()) {
            delay(3);
            coming = GPRS.read();
            if (coming == 'U') {          // read serial
              if (GPRS.available()) {
                delay(3);
                coming = GPRS.read();
                if (coming == 'M') {      // still reading the serial
                  if (GPRS.available()) {
                    delay(3);
                    coming = GPRS.read();
                    if (coming == 'P') {  // still reading the serial
                      if (GPRS.available()) {
                        delay(3);
                        coming = GPRS.read();
                        if (coming == 'o') {
                          digitalWrite(PUMP, HIGH); // write HIGH to the BULB pin  when The Recieved massage is MATCHED
                          text = "PUMP ON";
                          SMSsend(text);            // sending the above massage if commands successfully executed
                        }
                        else if (coming == 'c') {
                          digitalWrite(PUMP, LOW);   // write LOW to the BULB pin  when The Recieved massage is MATCHED
                          text = "PUMP  OFF";
                          SMSsend(text);             // sending the above massage if commands successfully executed
                        }</p><p>


You may Download !!!</p>

This program can control Five devices via SMS and can replay to user that everything is fine.

Step 8: SMS + Voice Calls Control and Security Things Codes

This program will provide by a fine techniques about how voice calls can made when a sensor sense movement or heating or an action happen that you want to be informed directly. we will use a push bottom as a sensor just to test the function of voice calling. You can use Tens different sensors you need such as PIR, Ping, IR, laser, and more...

At the same time you can control application and do your security things.

The codes is quite easy

<p>/*<br>Commands
SEND #LEDo   // GREEN LED ON   
SEND #LEDc   // GREEN LED OFF
SEND #BULBo  // BLUE LED ON 
SEND #BULBc  // BLUE LED OFF
IF THE DIGITAL PIN (4)INPUT GOES "LOW" CALL SOMEONE
*/</p>
<p>#include <br>SoftwareSerial GPRS(2, 3);</p><p>char inchar;
String text = ""; </p>
<p>void setup() {<br>  // set up digital output pins to control
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(4, INPUT);
  digitalWrite(12, LOW); // default state for I/O pins at power-up or reset,
  digitalWrite(11, LOW);// change as you wish.
 // initialize network location
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  delay(3000);      // give the GSM module time to initialize network location
  digitalWrite(7, LOW);
  
 //Initialize the GSM module serial port for communication.
  GPRS.begin(19200);
  delay(2000);
  GPRS.println("AT+CMGF=1");
  delay(100);
  GPRS.println("AT+CNMI=1,2,0,0,0");
  delay(100);
  GPRS.println("AT+CMGD=1,4");// delete all SMS
  delay(1000); 
  SMSsend("SYSTEM IS On");//2    
  GPRS.flush();   // delete all SMS at the first boot 
  delay(100);
}</p>
<p>void callSomeone() // Functoin for enable calling<br>{
GPRS.println("ATD +966566996070;"); // dial the phone number xxxxxxxxxx
// change("ATD +966xxxxxxxxx to your desired phone number (replace +966 with area code)
delay(100); // wait 100 mseconds.
//GPRS.println("ATH"); // end call function
//delay(60000); // maybe needed especially for analoge sensors 
}</p>
<p>void SMSsend(String massage) { <br>    GPRS.print("AT+CMGF=1\r");  //  Carriage return
    delay(100);
    GPRS.println("AT+CMGS=\"0566996070\""); // replace x by your number ("AT+CMGS=\"+966xxxxxxxxx\""); to yours
    delay(100);                            // (+966) is the country code replace it with yours 
    GPRS.println(massage);  
    delay(100);
    GPRS.println((char)26);//the message stopping character
    delay(100);
    GPRS.println();
    delay(100);
    GPRS.println("AT+CMGD=1,4");  // some AT Commands
    delay(100);
    GPRS.println("AT+CMGF=1");
    delay(100);
    GPRS.println("AT+CNMI=1,2,0,0,0");
    delay(200);
    text = ""; 
  }</p><p>void sms() {<br> while (GPRS.available()) {   // If a character comes in from the cellular module... 
      delay(3);                  // Delay time in between to improve stability
      inchar = GPRS.read();
      if (inchar == '#') {        // the start of our command
        if (GPRS.available()) {
          delay(3);
          inchar = GPRS.read();
          if (inchar == 'L') {   
            if (GPRS.available()) {
              delay(3);
              inchar = GPRS.read();
              if (inchar == 'E') {
                if (GPRS.available()) {
                  delay(3);
                  inchar = GPRS.read();
                  if (inchar == 'D') { 
                    if (GPRS.available()) {
                      delay(3);
                      inchar = GPRS.read();
                      if (inchar == 'o') {
                        digitalWrite(12, HIGH); // write high to the ledpin  when data match the conditions.
                 /*4*/  SMSsend("GREEN LED ON");     // sending the massage  to the user mobile 
                      }
                      else if (inchar == 'c') {
                        digitalWrite(12, LOW); // write low to the led pin when data match the conditions.
                 /*5*/   SMSsend("GREEN LED OFF");// sending the massage  to the user mobile 
                      }
                    }
                  }
                }
              }
            }
          }
          else if (inchar == 'B') { // Delay time in between to improve stability 
            if (GPRS.available()) {
              delay(3);
              inchar = GPRS.read();
              if (inchar == 'U') {// read serial
                if (GPRS.available()) {
                  delay(3);
                  inchar = GPRS.read();
                  if (inchar == 'L') {
                    if (GPRS.available()) {
                      delay(3);
                      inchar = GPRS.read();
                      if (inchar == 'B') {
                        if (GPRS.available()) {
                          delay(3);
                          inchar = GPRS.read();
                          if (inchar == 'o') {
                            digitalWrite(11, HIGH); // write high to the led pin
                          text = "BLUE LED ON";
                          SMSsend(text); // send massage to the user mobile
                          }
                          else if (inchar == 'c') {
                           digitalWrite(11, LOW);// write low to the led pin
                          text = "BLUE LED OFF";
                          SMSsend(text); // send massage to the user mobile
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
   }
 }
void loop(){
  sms();
  delay(1);
  if (digitalRead(4) == LOW)// this is the push buttom used as a sensor 
{
  callSomeone();
}
}</p>

You can have HERE

Step 9: TCP Web Client Uploading Data Things Speaks Codes

This program is for monitoring thing through Things Speaks Cloud. You can use for any sensors you like such as Temperature, Humidity, Pressure, Power meter, ... etc. You simply can monitors what ever you want over the internet by sending the sensors information to the cloud then from any where can access to these real - time data. I m using the Dallas Temperature Sensor as an Example. please connect the sensor data pin to the arduino digital pin 6.

codes below:

<p>#include <br>#include 
#include 
OneWire oneWire(6);// data pin of the sensor
DallasTemperature DS18B20(&oneWire);
SoftwareSerial GPRS(2, 3);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count = 0;   // counter for buffer array
int setupStep = 0;
int value1;//Celsius
int value2;//Fahrenheit</p>
<p>void setup()<br>{
  GPRS.begin(9600);// the GPRS baud rate
  DS18B20.begin();
  Serial.begin(9600);             // the Serial port of Arduino baud rate.
}</p>
<p>void loop() {</p><p>  DS18B20.requestTemperatures(); 
  value1 = DS18B20.getTempCByIndex(0); // Sensor  will capture Temp in Celcius
  value2 = DS18B20.getTempFByIndex(0); // Sensor  will capture Temp in Fahrenheit</p><p>   Send_pubnub();
   delay(1);
   setupStep = 0;
}</p>
<p>void clearBufferArray()              // function to clear buffer array<br>{
  for (int i = 0; i < count; i++)
  {
    buffer[i] = NULL; // clear all index of array with command NULL
  }
}</p>
<p>void Send_pubnub() {</p><p>  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
  {
    while (GPRS.available())         // reading data into char array
    {
      buffer[count++] = GPRS.read();   // writing data into array
      if (count == 64)break;
    }
    Serial.write(buffer, count);           // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero
  }
  if (setupStep < 15) {
    ConnectToInternet(setupStep);
    delay(1000);</p><p>    return Send_pubnub();
  }
}</p><p>void ConnectToInternet(int step) {</p><p>  int delayT = 1000;</p><p>  if (step == 0) {
    GPRS.println("AT");
    delay(delayT);
  }</p><p>  if (step == 1) {
    GPRS.println("AT+CPIN?");
    delay(delayT);
  }</p><p>  if (step == 2) {
    GPRS.println("AT+CREG?");
    delay(250);
  }</p><p>  if (step == 3) {
    GPRS.println("AT+CGATT?");
    delay(delayT);
  }</p><p>  if (step == 4) {
    GPRS.println("AT+QIDEACT");
    delay(delayT);
  }</p><p>  if (step == 5) {
    GPRS.println("AT+QISTAT=?");
    delay(250);
  }</p><p>  if (step == 6) {
    GPRS.println("AT+QIMUX=0");
    delay(250);
  }</p><p>  if (step == 7) {
    GPRS.println("AT+QIREGAPP=\"zain\","",""");// replace by your sim card APN my Apn = zain and password + user name is not set so its empety
    delay(delayT);
  }</p><p>  if (step == 8) {
    GPRS.println("AT+QIACT");
    delay(delayT);
  }</p><p>  if (step == 9) {
    GPRS.println("AT+QILOCIP");//get local IP adress
    delay(250);
  }
  if (step == 10) {
    GPRS.println("AT+QIPROMPT=0"); //No prompt ">" and show "SEND OK" when sending successes
    delay(delayT);
    delay(250);
  }</p><p>  if (step == 11) {
    GPRS.println("AT+QIOPEN=\"TCP\",\"184.106.153.149\",\"80\"");  GPRS.println("AT+QIOPEN=\"TCP\",\"184.106.153.149\",\"80\""); // 184.106.153.149 is the Thing Speak IP</p><p>    delay(delayT);
    delay(2000);
  }</p><p>  if (step == 12) {
    GPRS.println("AT+QISEND");
    delay(delayT);
    // delay(2000); //More delay time could be require depend on network
  }
  if (step == 13) {

// replace with your API key=206IRXXXXXXHJZUN<br>
    String str ="GET <a href="https://api.thingspeak.com/update?api_key=206IRORJO5AHJZUN&field1="> <a> https://api.thingspeak.com/update?api_key=206IROR...</a>> + String(value1)+ "&field2=" + String(value2);
    GPRS.println(str);
    delay(delayT);
    //delay(2000);//More delay time could be require depend on network
  }
  if (step == 14) {
    GPRS.println((char)26);// ASCII code of CTRL+Z
    GPRS.println();
    delay(delayT);
    //delay(2000);//More delay time could be require depend on network
  }
  setupStep++;
}</p>

You can have HERE

Step 10: Real-time GPS Tracking Via SMS Codes

This program can provide user by GPS location if a SMS is sent.

please connect tx/rx of the GPS to arduino digital pin 8 / 9.

SEND Do to have the location

The Codes!!

<p>/********************************************************************<br> *  AltSoftSerial always uses these pins for Serial communication:  *
 *                                                                  *
* Board          Transmit  Receive   PWM Unusable                   *
* -----          --------  -------   ------------                   *
* Teensy 3.0 & 3.1  21        20         22                         *
* Teensy 2.0         9        10       (none)                       *
* Teensy++ 2.0      25         4       26, 27                       *
* Arduino Uno        9         8         10                         *
* Arduino Leonardo   5        13       (none)                       *
* Arduino Mega      46        48       44, 45                       *
* Wiring-S           5         6          4                         *
* Sanguino          13        14         12                         *
*********************************************************************/</p>
<p>#include <br>#include 
#include 
SoftwareSerial GPRS(2, 3); // RX, TX
TinyGPSPlus gps; // The TinyGPS++ object for interfacing with the GPS
AltSoftSerial ss;
char c;</p><p>void setup() {
  pinMode(12,OUTPUT);
  pinMode(7, OUTPUT);
  Power_gsm();
  ss.begin(9600); // begin the GPS serial connection
  GPRS.begin(9600);  // Start software serial
  delay(2000);
  GPRS.println("AT+CMGF=1"); // AT+CMGF Select SMS Massage Format
  delay(100);
  GPRS.println("AT+CNMI=1,2,0,0,0"); // AT+CNMI New SMS Massage INdication
  delay(100);
  GPRS.println("AT+CMGD=1,4"); // AT+CMGD=1,4 Range of SMS on SIM card Can be deleted
  delay(1000);
  //SMSsend("SYSTEM IS ON:)");//2
  GPRS.flush(); // deleting all massages at the first boot
  delay(100);
}</p>
<p>void loop() {</p><p>  while (ss.available() > 0) 
    if (gps.encode(ss.read())) 
      while (GPRS.available()) {
        delay(3);
        c = GPRS.read();
        if (c == 'D') { 
          if (GPRS.available()) {
            delay(3);
            c = GPRS.read();
            if (c == 'o') {
            digitalWrite(12,HIGH);
            Senddata();
            }
            else if (c == 'c') {
            digitalWrite(12, LOW); 
           }
         }
       }
    }
   GPRS.flush();
 }</p>
<p>void Power_gsm() {<br>  digitalWrite(7, HIGH);
  delay(3000);
  digitalWrite(7, LOW);
}</p>
<p>void Senddata() {<br>  GPRS.print("AT+CMGF=1\r");  //  Carriage return
  delay(100);
  GPRS.println("AT+CMGS=\"+966566996070\""); // replace x by your number ("AT+CMGS=\"+966xxxxxxxxx\""); to yours
  delay(100);                            // (+966) is the country code replace it with yours
  GPRS.print("https://www.google.com/maps/place/");
  GPRS.print(gps.location.lat(), 6); 
  GPRS.print(","); 
  GPRS.print(gps.location.lng(), 6);
  GPRS.println((char)26);
  GPRS.println();
  delay(100);
  GPRS.println("AT+CMGD=1,4");  // some AT Commands
  delay(100);
  GPRS.println("AT+CMGF=1");
  delay(100);
  GPRS.println("AT+CNMI=1,2,0,0,0");
  delay(200);
}</p>

You can have HERE

Step 11: Real-time GPS Tracker and Display GPS Data on Google Maps Over the Internet

GO back to step 4 and 5 if you have done all require thing you can know use the coming program to display a real time GPS Location on Google maps.

Now double click on your webpage "index.html" that you already saved on step 5 and wait for some time. It will take some time to load the map and marker. If you have done everything right, then you will get the following output.

<p>/********************************************************************<br> *  AltSoftSerial always uses these pins for Serial communication:  *
 *                                                                  *
* Board          Transmit  Receive   PWM Unusable                   *
* -----          --------  -------   ------------                   *
* Teensy 3.0 & 3.1  21        20         22                         *
* Teensy 2.0         9        10       (none)                       *
* Teensy++ 2.0      25         4       26, 27                       *
* Arduino Uno        9         8         10                         *
* Arduino Leonardo   5        13       (none)                       *
* Arduino Mega      46        48       44, 45                       *
* Wiring-S           5         6          4                         *
* Sanguino          13        14         12                         *
*********************************************************************/</p><p>#include 
#include 
#include 
TinyGPSPlus gps;
AltSoftSerial ss;
SoftwareSerial GPRS(2, 3);</p><p>unsigned char buffer[64]; // buffer array for data recieve over serial port
int fixed = 0;
int count = 0;   // counter for buffer array
//int led = 13;
int setupStep = 0;
double longi = gps.location.lng();
double lati = gps.location.lat();</p>
<p>void setup()<br>{
  
  ss.begin(9600); //Start GPS
  GPRS.begin(9600);               // the GPRS baud rate
  Serial.begin(19200);             // the Serial port of Arduino baud rate.
  delay(10000);
}</p><p>void loop() {</p><p>   longi = gps.location.lng();
   lati = gps.location.lat();
   GPSCord();
   Send_pubnub();
   delay(1);
   setupStep = 0;
}</p><p>void clearBufferArray()              // function to clear buffer array
{
  for (int i = 0; i < count; i++)
  {
    buffer[i] = NULL; // clear all index of array with command NULL
  }
}</p>
<p>void GPSCord(){<br>  while (ss.available() > 0)
  gps.encode(ss.read());</p><p>  if (gps.location.isUpdated())
  {
    fixed = 1;
  //  Serial.print("LAT="); Serial.print(gps.location.lat(), 6);
  //  Serial.print(" LNG="); Serial.println(gps.location.lng(), 6);
  }</p><p>  if(fixed ==0)
  {
   //  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   //  delay(300);               // wait for a second
   //  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   //  delay(300);  
   // Serial.print("NO GPS Signal Detected");
  }
  if (gps.altitude.isUpdated())
  {
    //Serial.print("Altitude:");
    //Serial.println(gps.altitude.meters());
  }
}</p>
<p>void ConnectToInternet(int step) {</p><p>  int delayT = 1000;</p><p>  if (step == 0) {
    GPRS.println("AT");
    delay(delayT);
  }</p><p>  if (step == 1) {
    GPRS.println("AT+CPIN?");
    delay(delayT);
  }</p><p>  if (step == 2) {
    GPRS.println("AT+CREG?");
    delay(250);
  }</p><p>  if (step == 3) {
    GPRS.println("AT+CGATT?");
    delay(delayT);
  }</p><p>  if (step == 4) {
    GPRS.println("AT+QIDEACT");
    delay(delayT);
  }</p><p>  if (step == 5) {
    GPRS.println("AT+QISTAT=?");
    delay(250);
  }</p><p>  if (step == 6) {
    GPRS.println("AT+QIMUX=0");
    delay(250);
  }</p><p>  if (step == 7) {
    GPRS.println("AT+QIREGAPP=\"zain\","",""");
    delay(delayT);
  }</p><p>  if (step == 8) {
    GPRS.println("AT+QIACT");
    delay(delayT);
  }</p><p>  if (step == 9) {
    GPRS.println("AT+QILOCIP");//get local IP adress
    delay(250);
  }
  if (step == 10) {
    GPRS.println("AT+QIPROMPT=0"); //No prompt ">" and show "SEND OK" when sending successes
    delay(delayT);
    delay(250);
  }</p><p>  if (step == 11) {
    GPRS.println("AT+QIOPEN=\"TCP\",\"184.106.153.149\",\"80\"");
    delay(delayT);
    delay(2000);
  }</p><p>  if (step == 12) {
    GPRS.println("AT+QISEND");
    delay(delayT);
    // delay(2000); //More delay time could be require depend on network
  }
  if (step == 13) {
    String str="GET <a href="https://api.thingspeak.com/update?api_key=206IRORJO5AHJZUN&field4="> https://api.thingspeak.com/update?api_key=206IROR...</a> + String(lati,6)+ "&field5=" + String(longi,6);
    GPRS.println(str);
    delay(delayT);
    //delay(2000);//More delay time could be require depend on network
  }
  if (step == 14) {
    GPRS.println((char)26);// ASCII code of CTRL+Z
    GPRS.println();
    delay(delayT);
    //delay(2000);//More delay time could be require depend on network
  }
  setupStep++;
}</p>

You can have HERE

The HTML index HERE

Step 12: Conclusion

I hope you enjoy This journey and If you have any Question you are welcome to ask.

I m sorry If there something go wrong. Every one welcome to correct me.

Have fun making great project!!

Please Share your great project and lets learn more!

Microcontroller Contest

Participated in the
Microcontroller Contest