In this project, we aim to create a simple method of keeping track of the target's location using a microcontroller - specifically the Arduino UNO and a GPS module. The data collected on by the module is uploaded on a cloud service called ThingSpeak which is commonly used for IoT applications. ThingSpeak also has supports RESTful API which we have to used to create a simple android app to download the latitude and longitude of the tracker at the press of a button.
GPS stands for Global Positioning System. It is a radio navigating system and was originally devised by the US Department of Defence for military use and later made available to civilians for daily use. It uses a constellation of 24 nominal satellites which pin point the location of the target. All the satellites works synchronously with respect to an atomic clock on the ground. The basic principle used is the time taken for the radio waves transmitted by the satellites help us in realising the location of the target.
In this project, we have used the GPS Module NEO-6M which is capable of finding various details of location where it has been placed. We take the data sent to the Arduino from the NEO-6M and use a simple parsing code to get the data relevant to the project - the Latitude and Longitude. This data is then written onto a ThingSpeak channel and can tracked by us given that the Arduino is powered up. The ThingSpeak API is used to create an Android App to get the data on a mobile device.
Through this project we hope to create a system such that when the location of the vehicle is requested through the device via SMS ,we should be getting a message back with the latitude and longitude data.In terms of the academics,we shall understand basic embedded system design, GSM communication, GPS tracking systems and also a lot about the modules in use.
#include <WiFi.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <HTTPClient.h>
static const int RXPin = 16, TXPin = 17;
static const uint32_t GPSBaud = 9600;
double latitude;
double longitude;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
const char* ssid = "Redmi Note 10S";
const char* password = "gagan123";
// Domain Name with full URL Path for HTTP POST Request
const char* serverName = "http://api.thingspeak.com/update";
// write API Key provided by thingspeak
String apiKey = "M6WM5NWRF4VU0SFM";
void setup(){
Serial.begin(9600);
ss.begin(GPSBaud);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
}
void loop(){
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0 and WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
latitude=gps.location.lat();
Serial.print(latitude);
Serial.print(" Longitude= ");
longitude=gps.location.lng();
Serial.println(longitude);
http.begin(client, serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData1 = "api_key=" + apiKey + "&field1=" + String(latitude);
int httpResponseCode1 = http.POST(httpRequestData1);
String httpRequestData2 = "api_key=" + apiKey + "&field2=" + String(longitude);
int httpResponseCode2 = http.POST(httpRequestData2);
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode1);
http.end();
}
}
}
The data gathered by the gps moduel is written, onto ThingSpeak server and later downloaded onto an android app have been added to this github repo for your persual - https://github.com/RITApragya/GPSTrackingUsingUNO
The app has been made on Android Studio using Kotlin. This app uses REST API to get data from ThingSpeak and display in text views at the press of a button.
RESTful API is an API Architecture which through HTTP protocols performs CRUD (Creating, Reading, Updating, Deleting) functions within or from a database.
ROBO POJO Generator Plugin has been used to create a kt class compaitible with the format of data sent back from the cloud via a JSON file. The format of the response (which uses GET Protocol) was found on the the ThingSpeak API documentation page - https://in.mathworks.com/help/thingspeak/readlastentry.html The Retrofit library has been used to easily make the API calls which is handled by the ApiService.kt file which has the required queries in the getCurrentLocation function. The only query we have is a constant one which is nothing but the API Key which is already a string saved in the ApiConfig.kt file. Said file also calls ApiService class and establishes contact with the API. Finally, the MainViewModel is the final model which helps us unify the UI and the backend. It calls the ApiConfig file, handles the loading case, error case and also stores the loaction in _LocaitonData which is a LiveData object. In the MainActivity.kt, the string for the final response is created which is appended to the response from the CurrentLocaitonResponse file which now has the live values of the Latitude and Longitude and also time is another output which we get from a standard Java library. The UI was made using the design view of the activity_main.xml in ConstraintLayout.
We successfully found the co-ordinates of the location with the help of the NEO-6M GPS module and stored in on a cloud server for easy remote access.
Through this project, we gained understanding on various aspects of Embedded Systems like the Arduino UNO and the GPS Module. We also gained insight into the conception and principles of GPS. We also used the tinyGPS and WiFi libraries which improved our knowledge of Arduino C++. Also accrued preliminary knowledge on APIs and Android Development.
Shreyas lal
srinkith h
Mohammed Kaif
lakshya Singal
Report prepared on May 6, 2024, 7:06 p.m. by:
Report reviewed and approved by Aditya Pandia [CompSoc] on May 9, 2024, 10:49 p.m..