Вы находитесь на странице: 1из 9

#include <LiquidCrystal.

h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int analogPin = A3; // pin that the sensor is attached to
const int buttonPin = 2;
int buttonState = 0;
const int threshold = 400;
int Gpsdata; // for incoming serial data
unsigned int finish =0; // indicate end of message
unsigned int pos_cnt=0; // position counter
unsigned int lat_cnt=0; // latitude data counter
unsigned int log_cnt=0; // longitude data counter
unsigned int flg =0; // GPS flag
unsigned int com_cnt=0; // comma counter
char lat[20]; // latitude array
char lg[20]; // longitude array
String a;
String b;
String c;
String d;
String f;
String g;
String h;
String l;
String m;
String n;

void Receive_GPS_Data();
void setup()
{
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
int analogValue = analogRead(analogPin);

Receive_GPS_Data();

a = lat;
c = lg;
d = c;
b = a;
a.remove(2,7);
b.remove(0,2);
c.remove(3,8);
d.remove(0,3);
f = b;
g = b;
l = d;
m = d;
g.remove(2,7);
f.remove(0,3);
l.remove(2,7);
m.remove(0,3);
h = g+f;
n = l+m;
int o=(c.toInt());
int e=(a.toInt());
double i=(h.toInt());
double p=(n.toInt());
i = i/10000;
p = p/10000;
double j=e+(i/60);
double q=o+(p/60);
String k = String(j,6);
String r = String(q,6);
String s = "http://maps.google.com/?q=";
String t = s+k+","+r;
Serial.print("Location : ");
Serial.println(t);
lcd.clear();
lcd.print("LATI:");
lcd.print(lat);
lcd.setCursor(0,1);
lcd.print("LONGI:");
lcd.print(lg);

finish = 0;pos_cnt = 0;
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
Serial.println("AT"); //text/message mode
delay(100);
Serial.println("AT+CMGF=1"); //text/message mode
delay(100);
Serial.println("AT+CMGS=\"+919367606225\"\r");//ph no
which message is to be sent
delay(100);
Serial.println("PERSON IS AT");
delay(100);
Serial.println(t);
delay(100);
Serial.println((char)26);
delay(2000);
Serial.println("AT+CMGS=\"+918680847306\"\r");//ph no
which message is to be sent
delay(100);
Serial.println("PERSON IS AT");
delay(100);
Serial.println(t);
delay(100);
Serial.println((char)26);
delay(2000);
digitalWrite(ledPin, LOW);
}
}
void Receive_GPS_Data()
{
while(finish==0){
while(Serial.available()>0){ // Check GPS data
Gpsdata = Serial.read();
flg = 1;
if( Gpsdata=='$' && pos_cnt == 0) // finding GPRMC
header
pos_cnt=1;
if( Gpsdata=='G' && pos_cnt == 1)
pos_cnt=2;
if( Gpsdata=='P' && pos_cnt == 2)
pos_cnt=3;
if( Gpsdata=='R' && pos_cnt == 3)
pos_cnt=4;
if( Gpsdata=='M' && pos_cnt == 4)
pos_cnt=5;
if( Gpsdata=='C' && pos_cnt==5 )
pos_cnt=6;
if(pos_cnt==6 && Gpsdata ==','){ // count commas in
message
com_cnt++;
flg=0;
}

if(com_cnt==3 && flg==1){


lat[lat_cnt++] = Gpsdata; // latitude
flg=0;
}

if(com_cnt==5 && flg==1){


lg[log_cnt++] = Gpsdata; // Longitude
flg=0;
}

if( Gpsdata == '*' && com_cnt >= 5){


com_cnt = 0; // end of GPRMC message
lat_cnt = 0;
log_cnt = 0;
flg = 0;
finish = 1;

}
}
}
}

Вам также может понравиться