My neo 6m gps module reads location data on serial monitor when i test it alone but it wont read on my code so my gsm module just sends a blank message and my lcd displays latitude and longitude as 0.00.
Below is the code i used
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <TinyGPS++.h>
TinyGPSPlus gps;
SoftwareSerial gpsSerial(2, 3);
double latitude, longitude;
SoftwareSerial SIM800L(4,5);
String response;
int lastStringLength = response.length();
String link;
void setup() {
lcd.init();
lcd.backlight();
lcd.print("Vehicle Tracking");
delay(1000);
lcd.setCursor(0,1);
lcd.print(" System ");
delay(3000);
lcd.clear();
lcd.print("Initializing...");
delay(1000);
Serial.begin(9600);
Serial.println("GPS Ready");
delay(5000);
SIM800L.begin(9600);
delay(1000);
SIM800L.println("AT+CMGF=1");
Serial.println("SIM800L started at 9600");
delay(1000);
Serial.println("Setup Complete! System Ready!");
SIM800L.println("AT+CNMI=2,2,0,0,0");
lcd.clear();
lcd.print("System Ready");
delay(1000);
}
void loop() {
if (SIM800L.available()>0){
response = SIM800L.readStringUntil('\n');
}
if(lastStringLength != response.length()){
GPS();
//Perintah ON
if(response.indexOf("Track")!=-1){ //ganti FIND dengan keyword teman-teman
SIM800L.println("AT+CUSD=1,\"*556#\"\r"); // AT command for Balance request
delay(5000);
String balance = SIM800L.readStringUntil("64"); // Read string until 64 is found (end of message
Serial.print("Balance is = ");
Serial.print(balance);
delay(1000);
SIM800L.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CMGS=\"08125098892\"\r"); //ganti no hp kalian ya
delay(1000);
SIM800L.println("Your Vehicle Location: ");
SIM800L.println(link);// The SMS text you want to send
SIM800L.println(balance);
delay(100);
SIM800L.println((char)26);// ASCII code of CTRL+Z
delay(1000);
lcd.clear();
lcd.print("Lat:");
lcd.print(latitude,6);
lcd.setCursor(0,1);
lcd.print("Long:");
lcd.print(longitude,6);
delay(3000);
lcd.clear();
lcd.print("Message Sent");
delay(2000);
lcd.clear();
lcd.print("System Ready");
delay(1000);
}
}
}
void GPS(){
if(Serial.available()) {
gps.encode(Serial.read());
}
if(gps.location.isUpdated()) {
latitude = gps.location.lat();
longitude = gps.location.lng();
link = "www.google.com/maps/place/" + String(latitude, 6) + "," + String(longitude, 6) ;
Serial.println(link);
}
}
Below is the message i receive from my sim800l
Your Vehicle Location:
AT+CUSD=1,"*556#"
OK
+CUSD: 0, "Pulse Main Account:N1947.