Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **GPS SMS**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-03-17 06:06:41
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Upon receiving an SMS with "sendloc," the SIM900A */
- /* triggers the ESP32 to send GPS coordinates via */
- /* SMS. Activating pin D14 for 5 seconds sends the */
- /* location to a predefined number. Setting pin RX2 */
- /* high activates a specific function. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
- #include <sim900.h> //https://github.com/nthnn
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void sendLocation(); // Function to send GPS location
- void checkForSMS(); // Function to check for incoming SMS
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t b1_PushButton_PIN_D14 = 14;
- const uint8_t b2_PushButton_PIN_RX2 = RX2;
- /***** DEFINITION OF Software Serial *****/
- const uint8_t sim_SIM900A_Serial_PIN_SERIAL_TX_D4 = 4;
- const uint8_t sim_SIM900A_Serial_PIN_SERIAL_RX_D13 = 13;
- EspSoftwareSerial::UART sim_SIM900A_Serial;
- // Create an instance of the SIM900 class
- SIM900 sim900(&sim_SIM900A_Serial);
- // Create an instance of the EasyButton class
- EasyButton button(b1_PushButton_PIN_D14);
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(b1_PushButton_PIN_D14, INPUT_PULLUP);
- pinMode(b2_PushButton_PIN_RX2, INPUT_PULLUP);
- sim_SIM900A_Serial.begin(9600, SWSERIAL_8N1, sim_SIM900A_Serial_PIN_SERIAL_RX_D13, sim_SIM900A_Serial_PIN_SERIAL_TX_D4, false);
- // Initialize SIM900
- if (sim900.handshake()) {
- Serial.println("SIM900 is ready");
- } else {
- Serial.println("SIM900 initialization failed");
- }
- // Initialize EasyButton
- button.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- checkForSMS(); // Check for incoming SMS
- // Check button state
- button.update();
- if (button.isPressed()) {
- // Activate specific function when button is pressed
- digitalWrite(b2_PushButton_PIN_RX2, HIGH);
- delay(5000); // Keep it high for 5 seconds
- digitalWrite(b2_PushButton_PIN_RX2, LOW);
- }
- }
- // Function to check for incoming SMS
- void checkForSMS() {
- if (sim900.isCardReady()) {
- String sms = sim900.getResponse(); // Assuming this function retrieves SMS
- if (sms.indexOf("sendloc") != -1) {
- sendLocation(); // Call function to send location
- }
- }
- }
- // Function to send GPS location via SMS
- void sendLocation() {
- // Assuming we have a function to get GPS coordinates
- String location = "Latitude: 12.345678, Longitude: 98.765432"; // Example coordinates
- sim900.sendSMS("1234567890", location); // Replace with the predefined number
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement