Advertisement
pleasedontcode

**GPS SMS** rev_01

Mar 17th, 2025
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **GPS SMS**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-03-17 06:06:41
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Upon receiving an SMS with "sendloc," the SIM900A */
  21.     /* triggers the ESP32 to send GPS coordinates via */
  22.     /* SMS. Activating pin D14 for 5 seconds sends the */
  23.     /* location to a predefined number. Setting pin RX2 */
  24.     /* high activates a specific function. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
  31. #include <sim900.h> //https://github.com/nthnn
  32. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void sendLocation(); // Function to send GPS location
  38. void checkForSMS(); // Function to check for incoming SMS
  39.  
  40. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  41. const uint8_t b1_PushButton_PIN_D14     = 14;
  42. const uint8_t b2_PushButton_PIN_RX2     = RX2;
  43.  
  44. /***** DEFINITION OF Software Serial *****/
  45. const uint8_t sim_SIM900A_Serial_PIN_SERIAL_TX_D4       = 4;
  46. const uint8_t sim_SIM900A_Serial_PIN_SERIAL_RX_D13      = 13;
  47. EspSoftwareSerial::UART sim_SIM900A_Serial;
  48.  
  49. // Create an instance of the SIM900 class
  50. SIM900 sim900(&sim_SIM900A_Serial);
  51.  
  52. // Create an instance of the EasyButton class
  53. EasyButton button(b1_PushButton_PIN_D14);
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56.  
  57. void setup(void)
  58. {
  59.     // put your setup code here, to run once:
  60.  
  61.     pinMode(b1_PushButton_PIN_D14, INPUT_PULLUP);
  62.     pinMode(b2_PushButton_PIN_RX2, INPUT_PULLUP);
  63.  
  64.     sim_SIM900A_Serial.begin(9600, SWSERIAL_8N1, sim_SIM900A_Serial_PIN_SERIAL_RX_D13, sim_SIM900A_Serial_PIN_SERIAL_TX_D4, false);
  65.  
  66.     // Initialize SIM900
  67.     if (sim900.handshake()) {
  68.         Serial.println("SIM900 is ready");
  69.     } else {
  70.         Serial.println("SIM900 initialization failed");
  71.     }
  72.  
  73.     // Initialize EasyButton
  74.     button.begin();
  75. }
  76.  
  77. void loop(void)
  78. {
  79.     // put your main code here, to run repeatedly:
  80.     checkForSMS(); // Check for incoming SMS
  81.  
  82.     // Check button state
  83.     button.update();
  84.     if (button.isPressed()) {
  85.         // Activate specific function when button is pressed
  86.         digitalWrite(b2_PushButton_PIN_RX2, HIGH);
  87.         delay(5000); // Keep it high for 5 seconds
  88.         digitalWrite(b2_PushButton_PIN_RX2, LOW);
  89.     }
  90. }
  91.  
  92. // Function to check for incoming SMS
  93. void checkForSMS() {
  94.     if (sim900.isCardReady()) {
  95.         String sms = sim900.getResponse(); // Assuming this function retrieves SMS
  96.         if (sms.indexOf("sendloc") != -1) {
  97.             sendLocation(); // Call function to send location
  98.         }
  99.     }
  100. }
  101.  
  102. // Function to send GPS location via SMS
  103. void sendLocation() {
  104.     // Assuming we have a function to get GPS coordinates
  105.     String location = "Latitude: 12.345678, Longitude: 98.765432"; // Example coordinates
  106.     sim900.sendSMS("1234567890", location); // Replace with the predefined number
  107. }
  108.  
  109. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement