Smart GPS tracker system using aurdino
It will feature a GPS module to fetch the location coordinates (latitude and
longitude) and a GSM module to send such coordinates to a mobile device via
SMS.
How it Works:
GPS Module: NEO-6M is connected to an Arduino. The GPS communicates via
serial to fetch the coordinates of the current location.
The GSM module: This module, which will be the SIM800L, sends an SMS of
the coordinates to an already set phone number.
Microcontroller: It's the part where data, which comes from the GPS module,
is to be handled by Arduino Uno and instruct the GSM module to send an
SMS.
Code
#include <Wire.h>
SoftwareSerial Gsm(6, 7);
char phone_no[] = "+918310322559";
TinyGPS gps;
int state;
String textMessage;
void setup() {
Serial.begin(9600);
Gsm.begin(9600);
Serial.print("AT+CMGF=1\r");
delay(100);
Serial.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
pinMode(10, INPUT);
}
void loop() {
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
for (unsigned long start = millis(); millis() - start < 1000;) {
while (Serial.available()) {
char c = Serial.read();
Serial.print(c);
if (gps.encode(c))
newData = true;
}
}
if (Gsm.available() > 0) {
textMessage = Gsm.readString();
textMessage.toUpperCase();
delay(10);
}
state = digitalRead(10);
if (state == 0)
//Prateek
//www.justdoelectronics.com
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Gsm.print("AT+CMGF=1\r");
delay(400);
Gsm.print("AT+CMGS=\"");
Gsm.print(phone_no);
Gsm.println("\"");
Gsm.println("Alert I need help.............");
Gsm.print("http://maps.google.com/maps?q=loc:");
Gsm.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Gsm.print(",");
Gsm.print(flon == TinyGPS ::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
delay(200);
Gsm.println((char)26);
//Prateek
//www.justdoelectronics.com
delay(200);
Gsm.println();
Serial.println("SMS Sent");
Serial.println("Call");
delay(20000);
Gsm.println("ATD+91xxxxxxxxxx;");
delay(150000);
Gsm.println("ATH");
delay(1000);
} else {
delay(10);
}
Serial.println(failed);
}