0% found this document useful (0 votes)
14 views

Left One

The document contains code for tracking a vehicle's location using a GPS and GSM module connected to an Arduino. It initializes the hardware, finds the GPS location, sends an SMS alert with the location details, and displays status messages on an LCD screen.

Uploaded by

yasin Mohmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Left One

The document contains code for tracking a vehicle's location using a GPS and GSM module connected to an Arduino. It initializes the hardware, finds the GPS location, sends an SMS alert with the location details, and displays status messages on an LCD screen.

Uploaded by

yasin Mohmed
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <TinyGPS++.

h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);


SoftwareSerial gpsSerial(4, 3);
SoftwareSerial gsmSerial(7, 6);
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
int temp = 0;
char buffer[40];

void setup() {
Serial.begin(9600);
gpsSerial.begin(GPSBaud);
gsmSerial.begin(9600);
lcd.begin(16, 2);
}

void loop() {
serialEvent();

while (temp) {
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
// ...
}
}
// ...
}

void serialEvent() {
while (Serial.available() > 0) {
if (Serial.find("Track Vehicle")) {
temp = 1;
break;
} else {
temp = 0;
}
}
}

void gsm_init() {
lcd.clear();
lcd.print("Finding Module..");

boolean at_flag = 1;
while (at_flag) {
Serial.println("AT");
delay(1);

while (Serial.available() > 0) {


if (Serial.find("OK"))
at_flag = 0;
}

delay(1000);
}
lcd.clear();
lcd.print("Module Connected..");
delay(1000);
lcd.clear();
lcd.print("Disabling ECHO");

boolean echo_flag = 1;
while (echo_flag) {
Serial.println("ATE0");

while (Serial.available() > 0) {


if (Serial.find("OK"))
echo_flag = 0;
}

delay(1000);
}

lcd.clear();
lcd.print("Echo OFF");
delay(1000);
lcd.clear();
lcd.print("Finding Network..");

boolean net_flag = 1;
while (net_flag) {
Serial.println("AT+CPIN?");
while (Serial.available() > 0) {
if (Serial.find("+CPIN: READY"))
net_flag = 0;
}

delay(1000);
}

lcd.clear();
lcd.print("Network Found..");
delay(1000);
lcd.clear();
}

void init_sms() {
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+252906034727\""); // use your 10 digit cell no. here
delay(400);
}

void send_data(const char* message) {


Serial.print(message);
delay(200);
}

void send_sms() {
Serial.write(26);
}
void lcd_status() {
lcd.clear();
lcd.print("Message Sent");
delay(2000);
lcd.clear();
lcd.print("System Ready");
}

void tracking() {
init_sms();
send_data("Vehicle Tracking Alert:");
Serial.println(" ");
send_data("Your Vehicle Current Location is:");
Serial.println(" ");

snprintf(buffer, sizeof(buffer), "Latitude: %.6f", gps.location.lat());


send_data(buffer);

Serial.print("\n Longitude: ");


Serial.println(gps.location.lng(), 6);

snprintf(buffer, sizeof(buffer), "https://www.google.com/maps/@%.6f,%.6f,14z",


gps.location.lat(), gps.location.lng());
send_data(buffer);

send_sms();
delay(2000);
lcd_status();
}

You might also like