Virtual Expo 2024

GPS Tracker Using Arduino

Envision
Diode

Aim

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.

Introduction

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. 

Objective

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.

Components Used

  • Jumpers
  • Breadboard
  • ESP 32
  • GPS Module(Neo 6m)
  • Power Supply
  • Connecting Wires

Implementation   

#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();
    }
  }
}

EXPLANATION:

  • It initializes the necessary libraries and variables for GPS, WiFi, and HTTP communication.
  • Sets up a SoftwareSerial connection for the GPS module and connects to a specified WiFi network.
  • Continuously reads GPS data, extracts latitude and longitude information, and sends it to ThingSpeak using HTTP POST requests.
  • The latitude and longitude data are sent as separate fields (field1 and field2) along with the API key to the ThingSpeak server.
  • The code repeats this process in the loop, ensuring a continuous stream of GPS data is sent to the specified ThingSpeak channel.

         

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

App

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.

REST API

RESTful API is an API Architecture which through HTTP protocols performs CRUD (Creating, Reading, Updating, Deleting) functions within or from a database.

CODE

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.

Results

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.

Conclusion

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.

References

 

Mentees

Shreyas lal

srinkith h

Mohammed Kaif

lakshya Singal

 

Expo meet link 

https://meet.google.com/svh-yoaw-vhv                                                     

METADATA

Report prepared on May 6, 2024, 7:06 p.m. by:

  • Ritapragya Biswas [Diode]
  • Kushal Gowda C R [Diode]
  • Abhinav Bysani [Diode]

Report reviewed and approved by Aditya Pandia [CompSoc] on May 9, 2024, 10:49 p.m..

Check out more projects!