Advertisement
pleasedontcode

SMS Alert rev_01

Aug 2nd, 2024
300
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: SMS Alert
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-08-02 05:40:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a system that leverages the EasyButton */
  21.     /* library to detect button presses on pin D2, */
  22.     /* triggering the Sim800L module to send alerts or */
  23.     /* messages when the button state changes. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28. #include <Sim800L.h>    //https://github.com/SCRN92/Sim800L
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void onButtonPressed(); // Function prototype for button press handler
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t mb1_PushButton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. // Initialize the EasyButton object for the push button
  40. EasyButton mb1_PushButton(mb1_PushButton_PIN_D2);
  41.  
  42. // Initialize the Sim800L object (assuming default constructor is sufficient)
  43. Sim800L sim800l; // Create an instance of the Sim800L class
  44.  
  45. /****** FUNCTION DEFINITIONS *****/
  46. void setup(void)
  47. {
  48.     // Start the serial communication for debugging
  49.     Serial.begin(115200);
  50.    
  51.     // Initialize the button with the specified pin
  52.     mb1_PushButton.begin();
  53.    
  54.     // Set the pin mode for the button
  55.     pinMode(mb1_PushButton_PIN_D2, INPUT_PULLUP);
  56.    
  57.     // Register the button press callback function
  58.     mb1_PushButton.onPressed(onButtonPressed);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // Read the button state
  64.     mb1_PushButton.read();
  65.    
  66.     // Add any additional code to handle button presses here
  67. }
  68.  
  69. // Function to handle button press
  70. void onButtonPressed() {
  71.     Serial.println("Button pressed! Sending alert..."); // Debug message
  72.  
  73.     // Check if the Sim800L module is ready
  74.     if (sim800l.begin()) {
  75.         // Send an alert or message (example message)
  76.         sim800l.sendSMS("1234567890", "Alert: Button was pressed!"); // Replace with actual phone number
  77.     } else {
  78.         Serial.println("Sim800L not ready.");
  79.     }
  80. }
  81.  
  82. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement