GPRS Example

Gprs example

This example shows you how to calculate the geographic coordinates (Latitude and Logitude) using the GSM Shield2.


  • Arduino board
  • Arduino GSM Shield 2
  • SIM card with traffic data


Arduino GSM Shield mounted on Arduino board 
Mount your GSM Shield 2 on an Arduino board, insert the SIM card into dedicated slot and connect it to your pc using the USB cable.


To using this sketch you must include the "GSM.h" library, indicate the PIN number of the SIM and define your Access Point Name (APN) and insert login and password. 
Now you can upload this example in your Arduino board and after that the loading is completed you can open your Serial Monitor to display your position.

The position is calculate through the "gprsPosition.getPosition()" function contained into GSM.h library and it is shown on serial monitor with the Serial.print() function that it is initialized in setup function with Serial.begin(9600) command.

The complete code and its detailed description are shown down.

A simple Sketch that shows the Longitude and Latitude
using a GSM shield.
GSM shield attached
You have to change the apn, login and password.
If your SIM has PIN you have to set
created 3 Apr. 2015
by team (
// Library include
#include <GSM.h>
// SIM and Network constant
#define PINNUMBER ""         // if present, insert Your PIN here
#define apn "internet.wind"   // change the apn
//#define apn ""
//#define apn ""
//#define apn "wap.tim"
#define login ""             // insert your login
#define password ""           // insert your password
// initialize the library instance
GSM gsmAccess;           // GSM access: include a 'true' parameter for debug enabled
GPRS gprsAccess;         // GPRS access
GSMClient client;         // Client service for TCP connection
GSM2 gprsPosition;       // GPRS Posistioning system
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);// initialize Serial communication
// start GSM shield
Serial.println(" ");
Serial.print("Connecting GSM network...");
if (gsmAccess.begin(PINNUMBER) != GSM_READY)
  Serial.println("Error !");
  while (true);
Serial.println("Ok !");
Serial.println("Setting APN...");
gprsAccess.attachGPRS(apn, login, password);
Serial.print("APN :");
Serial.print("Login :");
Serial.print("Password :");
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Position: ");