Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- double latitude, longitude;
- TinyGPSPlus gps;
- SoftwareSerial SIM800L(7,6);
- SoftwareSerial gps_Serial(2,3);
- void setup() {
- Serial.begin(9600);
- Serial.println("GPS Mulai");
- gps_Serial.begin(9600);
- SIM800L.begin(9600);
- SIM800L.println("AT+CMGF=1");
- updateSerial();
- Serial.println("SIM800L started at 9600");
- delay(1000);
- Serial.println("Setup Complete! SIM800L is Ready!");
- SIM800L.println("AT+CNMI=1,2,0,0,0");
- updateSerial();
- }
- void GPS(){
- if(gps.location.isValid()) {
- Serial.print("https://www.google.com/maps/@");
- Serial.print("Latitude: ");
- Serial.println(gps.location.lat(), 6);
- Serial.print("Longitude: ");
- Serial.println(gps.location.lng(), 6);
- }
- Serial.println();
- Serial.println();
- delay(1000);
- }
- void loop() {
- if(Serial.find("ON")) {
- if(gps_Serial.available()>0) {
- gps.encode(gps_Serial.read());
- GPS();
- }
- Serial.println("AT"); //Once the handshake test is successful, it will back to OK
- updateSerial();
- Serial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
- updateSerial();
- delay(1000); // Delay of 1000 milli seconds or 1 second
- Serial.println("AT+CMGS=\"xxxxxxxxxxxx\""); // Replace x with mobile number
- updateSerial();
- delay(1000);
- Serial.println("www.google.com/maps/place/" + String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6));// The SMS text you want to send
- updateSerial();
- delay(100);
- SIM800L.println((char)28);// ASCII code of CTRL+Z
- delay(1000);
- SIM800L.write(28);
- }
- }
- void updateSerial()
- {
- delay(500);
- while (Serial.available())
- {
- Serial.write(Serial.read());//Forward what Serial received to Software Serial Port
- }
- while(Serial.available())
- {
- Serial.write( Serial.read());//Forward what Software Serial received to Serial Port
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement