SHARE
TWEET

Untitled

ibraheemsalem Jan 20th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <TinyGPS++.h>
  3.  
  4. #include <SoftwareSerial.h>
  5. double latitude, longitude;
  6. TinyGPSPlus gps;
  7. SoftwareSerial SIM800L(7,6);
  8. SoftwareSerial gps_Serial(2,3);
  9.  
  10. void setup() {
  11.   Serial.begin(9600);
  12.   Serial.println("GPS Mulai");
  13.   gps_Serial.begin(9600);
  14.  
  15.     SIM800L.begin(9600);
  16.     SIM800L.println("AT+CMGF=1");
  17.     updateSerial();
  18.     Serial.println("SIM800L started at 9600");
  19.     delay(1000);
  20.     Serial.println("Setup Complete! SIM800L is Ready!");
  21.     SIM800L.println("AT+CNMI=1,2,0,0,0");
  22.     updateSerial();
  23.    
  24. }
  25.  
  26. void GPS(){
  27.  
  28.   if(gps.location.isValid()) {
  29.     Serial.print("https://www.google.com/maps/@");
  30.     Serial.print("Latitude: ");
  31.     Serial.println(gps.location.lat(), 6);
  32.     Serial.print("Longitude: ");
  33.     Serial.println(gps.location.lng(), 6);
  34.    
  35.   }
  36.   Serial.println();
  37.   Serial.println();
  38.   delay(1000);
  39. }
  40.  
  41. void loop() {
  42.  
  43.       if(Serial.find("ON")) {
  44.        
  45.         if(gps_Serial.available()>0) {
  46.     gps.encode(gps_Serial.read());
  47.     GPS();
  48.   }
  49.            Serial.println("AT"); //Once the handshake test is successful, it will back to OK
  50.           updateSerial();
  51.  
  52.            Serial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  53.           updateSerial();
  54.           delay(1000);  // Delay of 1000 milli seconds or 1 second
  55.            Serial.println("AT+CMGS=\"xxxxxxxxxxxx\""); // Replace x with mobile number
  56.           updateSerial();
  57.           delay(1000);
  58.    
  59.          
  60.           Serial.println("www.google.com/maps/place/" + String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6));// The SMS text you want to send
  61.           updateSerial();
  62.           delay(100);
  63.           SIM800L.println((char)28);// ASCII code of CTRL+Z
  64.           delay(1000);
  65.           SIM800L.write(28);
  66.       }
  67.   }
  68.  
  69.    
  70.  
  71.  
  72.  
  73.  
  74. void updateSerial()
  75. {
  76.   delay(500);
  77.   while (Serial.available())
  78.   {
  79.      Serial.write(Serial.read());//Forward what Serial received to Software Serial Port
  80.   }
  81.   while(Serial.available())
  82.   {
  83.     Serial.write( Serial.read());//Forward what Software Serial received to Serial Port
  84.   }
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top