Hello, i am working on a project where i use an arduino mega, a sim800l module and a GPS module. When i tested each part on its own, they worked but when i put then together in a code they dont work. I am basically trying to use gps module for location if i am outside and if i am in a building to use the sim800l module but the gps doesnt seem to work. Even if i am using it outside it send only the location from the SIM800l module, the location from the gps doesnt seem to work(i tested the gps with another code and it worked tho). The wiring its correct, i tested them but i dont know to make it work. Can you please help me? This is what i tried :
void loop()
{
while (Serial2.available() > 0)
{
gps.encode(Serial2.read());
if (gps.location.isUpdated())
{
// Latitude in degrees (double)
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
lat_gps = gps.location.lat();
sprintf(Latitude_GPS_char,"%.6f",lat_gps);
Latitude_GPS = String(Latitude_GPS_char);
// Longitude in degrees (double)
Serial.print("Longitude= ");
Serial.println(gps.location.lng(), 6);
lon_gps = gps.location.lng();
sprintf(Longitude_GPS_char,"%.6f",lon_gps);
Longitude_GPS = String(Longitude_GPS_char);
}
responce = "";
if ( (Latitude_GPS!="") && (Longitude_GPS!="") )
{
Serial.println("Latitude: " + String(Latitude_GPS) + "\tLongitude: " + String(Longitude_GPS));
url = "script.google.com/macros/s/" + Script_ID + "/exec?value1=" + String(Latitude_GPS) + "&value2=" + String(Longitude_GPS);
}
else
{
Serial1.println("AT+CLBS=1,1"); delay(5000); //Request for location data
while (Serial1.available())
{
char letter = Serial1.read();
responce = responce + String(letter); //Store the location information in string responce
delay(1000);
}
Serial.print("Result Obtained as:"); Serial.print(responce); Serial.println("*******");
prepare_message(); delay(1000); //use prepare_message funtion to prepare the link with the obtained LAT and LONG co-ordinates
Serial.println("Latitude: " + Latitude + "\tLongitude: " + Longitude);
url = "script.google.com/macros/s/" + Script_ID + "/exec?value1=" + Latitude + "&value2=" + Longitude;
}`