I'm working on a project in which when I press reset button the arduino should send longitudes and latitudes to my phone. I'm a beginner and tried to join two codes, first code can send the message and the second code can get the lon and lat printed on the serial monitor.
First code--
int timesTosend=1;
int count=0;
char phone_no[]="+917771914436";
void setup()
{
Serial.begin(9600);
delay(2000);
Serial.println("AT+CMGF=1");
delay(200);
}
void loop()
{
while (count<timesTosend)
{
delay(1500);
Serial.print("AT+CMGS=\"");
Serial.print(phone_no);
Serial.println("\"");
while(Serial.read()!='>');
{
Serial.print("Hii If this message is sent then its a huge sucess for me");
delay(500);
Serial.write(0x1A);
Serial.write(0x0D);
Serial.write(0x0A);
delay(5000);
}
count++;
}
}
Second code--
#include <SoftwareSerial.h>
#include <TinyGPS.h>
long lat,lon; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(4, 3); // create gps sensor connection
TinyGPS gps; // create gps object
void setup(){
Serial.begin(9600); // connect serial
gpsSerial.begin(9600); // connect gps sensor
}
void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
// display position
Serial.print("Position: ");
Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
Serial.print("lon: ");Serial.println(lon); // print longitude
}
}
}
My code which is not working--
#include <SoftwareSerial.h>
#include <TinyGPS.h>
long lat,lon; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(4, 3); // create gps sensor connection
TinyGPS gps; // create gps object
void setup()
{
Serial.begin(9600); // connect serial
gpsSerial.begin(9600); // connect gps sensor
Serial.begin(9600);
delay(2000);
Serial.println("AT+CMGF=1");
delay(200);
}
int timesTosend=1;
int count=0;
char phone_no[]="+917771914436";
void loop()
{
while (count<timesTosend)
{
delay(1500);
Serial.print("AT+CMGS=\"");
Serial.print(phone_no);
Serial.println("\"");
while(Serial.read()!='>');
{
while(gpsSerial.available())
{
if(gps.encode(gpsSerial.read()))
{ // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
Serial.print(lat,lon);
delay(500);
Serial.write(0x1A);
Serial.write(0x0D);
Serial.write(0x0A);
delay(5000);
}
}
}
count++;
}
}
Please help me out by correcting my mistake in the code.