/********* 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: SMS Alert
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-08-02 05:40:36
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Develop a system that leverages the EasyButton */
/* library to detect button presses on pin D2, */
/* triggering the Sim800L module to send alerts or */
/* messages when the button state changes. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/evert-arias/EasyButton
#include //https://github.com/SCRN92/Sim800L
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void onButtonPressed(); // Function prototype for button press handler
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t mb1_PushButton_PIN_D2 = 2;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Initialize the EasyButton object for the push button
EasyButton mb1_PushButton(mb1_PushButton_PIN_D2);
// Initialize the Sim800L object (assuming default constructor is sufficient)
Sim800L sim800l; // Create an instance of the Sim800L class
/****** FUNCTION DEFINITIONS *****/
void setup(void)
{
// Start the serial communication for debugging
Serial.begin(115200);
// Initialize the button with the specified pin
mb1_PushButton.begin();
// Set the pin mode for the button
pinMode(mb1_PushButton_PIN_D2, INPUT_PULLUP);
// Register the button press callback function
mb1_PushButton.onPressed(onButtonPressed);
}
void loop(void)
{
// Read the button state
mb1_PushButton.read();
// Add any additional code to handle button presses here
}
// Function to handle button press
void onButtonPressed() {
Serial.println("Button pressed! Sending alert..."); // Debug message
// Check if the Sim800L module is ready
if (sim800l.begin()) {
// Send an alert or message (example message)
sim800l.sendSMS("1234567890", "Alert: Button was pressed!"); // Replace with actual phone number
} else {
Serial.println("Sim800L not ready.");
}
}
/* END CODE */