I am currently working on a vehicle tracker system sends the location of the vehicle when you message it, the project works fine after i upload the code on the arduino uno but it stops working properly when i unplug the usb cord and put it back or connect it to another power supply. So i have to upload another code on the arduino uno then reupload my original code before it continues working.
This is the code i used for the project
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
float lattitude,longitude;
float a[2];
float p;
SoftwareSerial gpsSerial(4,3);
SoftwareSerial gsmSerial(7,6);
TinyGPSPlus gps;
void setup(){
lcd.begin(16,2);
delay(1000);
Serial.begin(9600);
delay(1000);
gpsSerial.begin(9600);
delay(1000);
gsmSerial.begin(9600);
delay(1000);
lcd.clear();
lcd.print("Vehicle Tracking");
lcd.setCursor(0,1);
lcd.print(" System ");
gsmSerial.println("AT+CNMI=2,2,0,0,0");
Serial.println("AT+CNMI=2,2,0,0,0");
delay(3000);
lcd.clear();
lcd.print("Initializing...");
delay(3000);
lcd.clear();
lcd.print("System Ready");
delay(1000);
}
/---------------------------------------------------------------------------------------*/
void loop(){
while(gsmSerial.available()){
gsmSerial.read();
}
while(Serial.available()){
Serial.read();
}
get_gsm();
}
float *get_gps()
{
gpsSerial.listen();
//Serial.println("INSIDE get_gps");
while(1)
{
while (gpsSerial.available() > 0)
{ gps.encode(gpsSerial.read()); }
if (gps.location.isUpdated())
{
Serial.print("LAT="); Serial.println(gps.location.lat(), 6);
Serial.print("LONG="); Serial.println(gps.location.lng(), 6);
lattitude=gps.location.lat();
longitude=gps.location.lng();
break;
}
}
a[0]=lattitude;
a[1]=longitude;
return a;
}
/---------------------------------------------------------------------------------------/
void get_gsm()
{
gsmSerial.listen();
while(gsmSerial.available()>0)
{Serial.println("INSIDE gsmSerial.available");
char Track[] = "Track";
if(gsmSerial.find(Track))
{Serial.println("INSIDE track");
gsmSerial.println("AT+CMGF=1");
delay(1000);
gsmSerial.println("AT+CMGS=\"xxxxx\"\r"); //replace “x”s with phone number
delay(1000);
p=get_gps();
gsmSerial.listen();
Serial.print("Your Vehicle Location: ");
gsmSerial.print("Your Vehicle Location: ");
Serial.print("LATITUDE="); Serial.print(*p,6);
gsmSerial.print("LATITUDE=");gsmSerial.print(*p,6);gsmSerial.print(",");
Serial.print("LONGITUDE="); Serial.print(*(p+1),6);
gsmSerial.print("\nLONGITUDE=");gsmSerial.print(*(p+1),6);
Serial.print("https://maps.google.com/?q="); Serial.print(*(p+2),6);
gsmSerial.print("\n https://maps.google.com/?q=");
gsmSerial.print(*p,6);gsmSerial.print(",");
gsmSerial.print(*(p+1),6);
delay(100);
gsmSerial.println((char)26);
delay(1000);
lcd.clear();
lcd.clear();
lcd.print("Lat:");
lcd.print(*p,6);
lcd.setCursor(0,1);
lcd.print("Long:");
lcd.print(*(p+1),6);
delay(3000);
lcd.clear();
lcd.print("Message Sent");
delay(2000);
lcd.clear();
lcd.print("System Ready");
delay(1000);
}
}
}
Below is a picture of when it doesn’t work