Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- static const int RXPin = 2, TXPin = 3;
- static const uint32_t GPSBaud = 9600;
- // The TinyGPS++ object
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- SoftwareSerial ss(RXPin, TXPin);
- SoftwareSerial SIM800L(7,6);
- void setup()
- {
- Serial.begin(9600);
- ss.begin(GPSBaud);
- SIM800L.begin(9600);
- Serial.println(F("DeviceExample.ino"));
- Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
- Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
- Serial.println(F("by Mikal Hart"));
- Serial.println();
- }
- void loop()
- {
- // This sketch displays information every time a new sentence is correctly encoded.
- while (ss.available() > 0)
- if (gps.encode(ss.read()))
- displayInfo();
- if (millis() > 5000 && gps.charsProcessed() < 10)
- {
- Serial.println(F("No GPS detected: check wiring."));
- delay(10000);
- }
- }
- void displayInfo()
- {
- Serial.print(F("Location: "));
- if (gps.location.isValid())
- {
- Serial.print(gps.location.lat(), 6);
- Serial.print(F(","));
- Serial.print(gps.location.lng(), 6);
- static uint32_t prevmillis;
- if(millis() - prevmillis > 10000){
- SIM800L.println("AT+CMGF=1");
- SIM800L.println("AT+CMGS=\"xxxxxxxxxxxx\"");
- delay(500);
- SIM800L.println("www.google.com/maps/place/" + String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6));// The SMS text you want to send
- delay(100);
- SIM800L.write(13);
- SIM800L.write(26);
- prevmillis = millis();
- }
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement