so im currently trying to do a a project whereby if my sensor is active, it will display my location. but, it seems that when the sensor is active, it only display location of lat: 0.00 , long: 0.00 on my LCD display. help me to solve this problem.
#include <LiquidCrystal.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10);
char msg;
int knockPin = 7; // Use Pin 7 as our Input
int knockVal = HIGH; // This is where we record our shock measurement
boolean bAlarm = false;
int knockValue = digitalRead(6);
unsigned long lastKnockTime; // Record the time that we measured a shock
int knockAlarmTime = 500; // Number of milli seconds to keep the knock alarm high
static const int RXPin = 13, TXPin = 8;
static const int GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup ()
{
mySerial.begin(19200); // Setting the baud rate of GSM Module
delay(20000);
ss.begin(GPSBaud);
Serial.begin(115200);
Serial.println("GSM SIM900A BEGIN");
pinMode (knockPin, INPUT) ; // input from the KY-031
pinMode (6, OUTPUT);
lcd.begin(16, 2);
String latitude = String(gps.location.lat(),6);
String longitude = String(gps.location.lng(),6);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("VeCAS System");
lcd.setCursor(3,1);
lcd.print(">>Begin>>");
delay (5000);
}
void loop ()
{
knockVal = digitalRead (knockPin) ; // read KY-031 Value
if (knockVal == LOW) // If we see a knock
{
lastKnockTime = millis(); // record the time of the shock
// The following is so you don't scroll on the output screen
if (!bAlarm)
{
Serial.println("KNOCK, KNOCK");
bAlarm = true;
digitalWrite (6, HIGH);
Serial.println(knockVal);
delay(100);
while (ss.available() > 0)
gps.encode(ss.read());
if (gps.location.isUpdated())
lcd.clear();
lcd.setCursor(4,0);
lcd.print("KNOCK!");
lcd.setCursor(3,1);
lcd.print("Detected");
delay (5000);
lcd.clear();
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
lcd.setCursor(0,0);
lcd.print("LAT:");
lcd.setCursor(5,0);
lcd.print(gps.location.lat());
lcd.setCursor(0,1);
lcd.print("LON:");
lcd.setCursor(5,1);
lcd.print(gps.location.lng());
delay(1000);
lcd.clear();
}
}
else
{
if( (millis()-lastKnockTime) > knockAlarmTime && bAlarm)
{
Serial.println("no knocks");
bAlarm = false;
digitalWrite (6, LOW);
delay(100);
}
}
}
void gpsTrack()
{
lcd.clear();
lcd.setCursor(4,0);
lcd.print("KNOCK!");
lcd.setCursor(3,1);
lcd.print("Detected");
delay (5000);
lcd.clear();
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
lcd.setCursor(0,0);
lcd.print("LAT:");
lcd.setCursor(5,0);
lcd.print(gps.location.lat());
lcd.setCursor(0,1);
lcd.print("LON:");
lcd.setCursor(5,1);
lcd.print(gps.location.lng());
delay(1000);
lcd.clear();
}