Overview: GPS Tracker using A9G GPRS/GPS Module & Arduino
In this project, we will make GPS Tracker Project using A9G GPRS/GPS Module & Arduino. The Maduino A9G GPS Tracker is an IoT (Internet of things) Solution-based product that integrates a Microcontroller ATSAMD21G18, GRRS/GSM+GPS module A9G with best power management and storage.
A GPS tracker is a navigation device normally carried by a moving vehicle or person that uses the Global Positioning System (GPS) to track the device’s movements and determine its location. The recorded location data can either be stored within the tracking unit or transmitted to an Internet-connected device using the cellular (GPRS or SMS) unit. This allows the location to be displayed against a map backdrop either in real-time or when analyzing the track later, using GPS tracking software.
This post is a continuation of the previous tutorial: Getting Started with A9G GSM/GPRS+GPS Module with Arduino. I highly recommend you to go through the previous post first before moving here directly. The previous post contains all the information about A9/A9G GPRS/GSM Module as well as Maduino Zero A9G Board. All the detailed setup guide and device preparation is explained there.
You may refer to some previous GPS Tracker-based projects:
- Real Time GPS Tracker using ESP8266 & Blynk with Maps
- ESP32 GPS Tracker using L86 GPS Module & OLED Display
- GPS+GSM Based Vehicle Tracking System using Arduino
- LoRa Based Low Power GPS Tracker with Arduino & ESP8266
AT Commands for getting GPS Data
To turn ON/OFF the GPS, you can send the following command.
|
1 2 |
AT+GPS=1 //Turn ON GPS AT+GPS=0 //Turn OFF GPS |
The following AT Command is used to read NEMA information every 10 seconds.
|
1 |
AT+GPSRD=10 |
To stop retrieving NEMA information every 10 seconds, you can use send the following command.
|
1 |
AT+GPSRD=0 |
To get the GPS information in terms of Latitude & Longitude, you can use send the following command.
|
1 |
AT+LOCATION=2 |
Note: These commands are practically explained in Previous Post
How to get GPS Location information?
Copy the below code and upload it to the Maduino A9G Board using Arduino IDE. Once the code is uploaded the A9G GPS Tracker is ready.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#include <stdio.h> #include <string.h> #define DEBUG true int PWR_KEY = 9; int RST_KEY = 6; int LOW_PWR_KEY = 5; bool ModuleState=false; unsigned long timeCount; void setup() { pinMode(PWR_KEY, OUTPUT); pinMode(RST_KEY, OUTPUT); pinMode(LOW_PWR_KEY, OUTPUT); digitalWrite(RST_KEY, LOW); digitalWrite(LOW_PWR_KEY, HIGH); digitalWrite(PWR_KEY, HIGH); SerialUSB.begin(115200); while (!SerialUSB) { ; // wait for serial port to connect } Serial1.begin(115200); digitalWrite(PWR_KEY, LOW); delay(3000); digitalWrite(PWR_KEY, HIGH); delay(5000); ModuleState=moduleStateCheck(); if(ModuleState==false)//if it's off, turn on it. { digitalWrite(PWR_KEY, LOW); delay(3000); digitalWrite(PWR_KEY, HIGH); delay(5000); SerialUSB.println("Now turnning the A9/A9G on."); } //GPS test sendData("AT+GPS=1", 1000, DEBUG);//1: turn on GPS 0:Turn off GPS sendData("AT+GPSRD=10", 1000, DEBUG);//Read NEMA information every 10 seconds sendData("AT+LOCATION=2", 1000, DEBUG);//AT+LOCATION=X //1:Get base address, 2:get gps address //sendData("AT+CCID", 3000, DEBUG); //sendData("AT+CREG?", 3000, DEBUG); //sendData("AT+CGATT=1", 1000, DEBUG); //sendData("AT+CGACT=1,1", 1000, DEBUG); //sendData("AT+CGDCONT=1,\"IP\",\"CMNET\"", 1000, DEBUG); //sendData("AT+CIPSTART=\"TCP\",\"www.mirocast.com\",80", 2000, DEBUG); timeCount=millis(); SerialUSB.println("Maduino A9/A9G GPS Test Begin!"); } void loop() { if(millis()-timeCount>5000) { sendData("AT+LOCATION=2", 1000, DEBUG); timeCount=millis();//refresh } while (Serial1.available() > 0) { SerialUSB.write(Serial1.read()); yield(); } while (SerialUSB.available() > 0) { Serial1.write(SerialUSB.read()); yield(); } } bool moduleStateCheck() { int i = 0; bool state=false; for (i = 0; i < 10; i++) { String msg = String(""); msg = sendData("AT", 1000, DEBUG); if (msg.indexOf("OK") >= 0) { SerialUSB.println("A9/A9G Module had turned on."); state=true; return state; } delay(500); } return state; } String sendData(String command, const int timeout, boolean debug) { String response = ""; Serial1.println(command); long int time = millis(); while ((time + timeout) > millis()) { while (Serial1.available()) { char c = Serial1.read(); response += c; } } if (debug) { SerialUSB.print(response); } return response; } |
After uploading the code, open the Serial Monitor and set the baud rate to 115200. The Module will take some time to retrieve data from Satellite. And soon it will display the NEMA information as well as Latitude, Longitude Coordinates.
We can show our location where we are in https://www.gps-coordinates.net/
A9G GPS Tracker on OLED Display
Now let us add an extra OLED Display to the board so that we can retrieve GPS information on OLED display. We need two library for OLED Display.
1. Adafruit GFX Library: https://github.com/adafruit/Adafruit-GFX-Library
2. SSD130 OLED Library: https://github.com/adafruit/Adafruit_SSD1306
Now copy the below code and upload it to the Maduino A9G Board.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
#include <stdio.h> #include <string.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void(* resetFunc) (void) = 0; //declare reset function at address 0 #define DEBUG true int PWR_KEY = 9; int RST_KEY = 6; int LOW_PWR_KEY = 5; bool ModuleState=false; unsigned long timeCount; void setup() { pinMode(PWR_KEY, OUTPUT); pinMode(RST_KEY, OUTPUT); pinMode(LOW_PWR_KEY, OUTPUT); digitalWrite(RST_KEY, LOW); digitalWrite(LOW_PWR_KEY, HIGH); digitalWrite(PWR_KEY, HIGH); SerialUSB.begin(115200); //while (!SerialUSB) { ; // wait for serial port to connect } Serial1.begin(115200); digitalWrite(PWR_KEY, LOW); delay(3000); digitalWrite(PWR_KEY, HIGH); delay(5000); ModuleState=moduleStateCheck(); if(ModuleState==false)//if it's off, turn on it. { digitalWrite(PWR_KEY, LOW); delay(3000); digitalWrite(PWR_KEY, HIGH); delay(5000); SerialUSB.println("Now turnning the A9/A9G on."); } //GPS test sendData("AT+GPS=1", 1000, DEBUG);//1: turn on GPS 0:Turn off GPS sendData("AT+GPSRD=10", 1000, DEBUG);//Read NEMA information every 10 seconds sendData("AT+LOCATION=2", 1000, DEBUG);//AT+LOCATION=X //1:Get base address, 2:get gps address if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 Serial.println(F("SSD1306 allocation failed")); for (;;) { SerialUSB.println("Now reset the maduino zero"); delay(1000); resetFunc();//restart delay(20); } } delay(2000); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 10); //Display static text display.println("how2electronics.com!"); display.println("Maduino Zero A9/A9G GPS Tracker!"); display.display(); delay(2000); timeCount=millis(); SerialUSB.println("Maduino A9/A9G GPS Test Begin!"); display.clearDisplay(); } void loop() { if(millis()-timeCount>5000) { sendData("AT+LOCATION=2", 1000, DEBUG); timeCount=millis();//refresh } while (Serial1.available() > 0) { display.clearDisplay(); String cstring = Serial1.readString(); SerialUSB.print(cstring);//SerialUSB.write(Serial1.read()); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.println(cstring); display.display(); yield(); } while (SerialUSB.available() > 0) { Serial1.write(SerialUSB.read()); yield(); } } bool moduleStateCheck() { int i = 0; bool state=false; for (i = 0; i < 10; i++) { String msg = String(""); msg = sendData("AT", 1000, DEBUG); if (msg.indexOf("OK") >= 0) { SerialUSB.println("A9/A9G Module had turned on."); state=true; return state; } delay(500); } return state; } String sendData(String command, const int timeout, boolean debug) { String response = ""; Serial1.println(command); long int time = millis(); while ((time + timeout) > millis()) { while (Serial1.available()) { char c = Serial1.read(); response += c; } } if (debug) { SerialUSB.print(response); } return response; } |
After the code is uploaded, the A9G GSM/GPRS + GPS Module will take some time to get the data. Once it receives data, the information will be displayed on OLED Display.
You can check the next post of this Series here: Internet with A9G Low Power GPRS+GPS Module & Arduino









1 Comment
can you help me with connection diagram for above code….