i wanna calculate the location in 2D " LAT , LONG" by GPS and send them by using GSM module with ardunio , i tried to get the location and i succeed by using TinyGPS library .. and i sent a SMS to my phone number .. i have the code for GPS & GSM they work separately but when i collect them there is no error but they don't work ,.. so i need to collect them to send the lat & long in sms to my phone number .... i use GSM module " SIM900 " and GPS type " skylab "
GPS code:
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(9,8,7,6,5,4);
unsigned long fix_age;
SoftwareSerial GPS(2,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;
void setup(){
lcd.begin(16,4);
GPS.begin(9600);
Serial.begin(9600);
}
void loop(){
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.get_position(&lat, &lon, &fix_age);
getGPS();
Serial.print("Latitude : ");
Serial.print(LAT/100000,7);
Serial.print(" :: Longitude : ");
Serial.println(LON/100000,7);
lcd.setCursor(4,0);
lcd.print("latitude : ");
lcd.setCursor(4,1);
lcd.print(LAT/100000,7);
lcd.setCursor(0,2);
lcd.print("longitude : ");
lcd.setCursor(0,3);
lcd.print(LON/100000,7);
}
void getGPS(){
bool newdata = false;
unsigned long start = millis();
while (millis() - start < 1000)
{
if (feedgps ()){
newdata = true;
}
}
if (newdata)
{
gpsdump(gps);
}
}
bool feedgps(){
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}
return 0;
}
void gpsdump(TinyGPS &gps)
{
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
{
feedgps();
}
}
GSM_SMS code::
#include <SoftwareSerial.h>
SoftwareSerial SIM900(0,1);
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000); // give time to log on to network.
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"01018506234\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("Hello, world. This is a text message from an Arduino Uno."); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void loop()
{
sendSMS();
do {} while (1);
}