Advertisement
pleasedontcode

**SMS Module** rev_01

Dec 5th, 2024
46
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 Module**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-05 22:28:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a project utilizing the SIM900 GSM module */
  21.     /* for sending and receiving SMS messages. Ensure the */
  22.     /* SoftwareSerial interface on A0 and A1 is */
  23.     /* configured for seamless communication and */
  24.     /* implement basic command responses. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <SoftwareSerial.h>
  31. #include <sim900.h> //https://github.com/nthnn
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void sendSMS(const char* number, const char* message);
  37. void receiveSMS();
  38.  
  39. /***** DEFINITION OF Software Serial *****/
  40. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_TX_A0       = A0;
  41. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_RX_A1       = A1;
  42. SoftwareSerial gsm_SIM900A_Serial(gsm_SIM900A_Serial_PIN_SERIAL_RX_A1, gsm_SIM900A_Serial_PIN_SERIAL_TX_A0);
  43.  
  44. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  45.  
  46. void setup(void)
  47. {
  48.     // Initialize GSM module communication
  49.     gsm_SIM900A_Serial.begin(9600);
  50.     Serial.begin(9600); // Initialize serial monitor communication
  51.     Serial.println("GSM Module Ready");
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // Example of sending an SMS
  57.     sendSMS("+1234567890", "Hello from Arduino!");
  58.  
  59.     // Check for incoming SMS
  60.     receiveSMS();
  61.  
  62.     delay(10000); // Wait for 10 seconds before sending another SMS
  63. }
  64.  
  65. void sendSMS(const char* number, const char* message) {
  66.     gsm_SIM900A_Serial.print("AT+CMGF=1\r"); // Set SMS to text mode
  67.     delay(100);
  68.     gsm_SIM900A_Serial.print("AT+CMGS=\"");
  69.     gsm_SIM900A_Serial.print(number);
  70.     gsm_SIM900A_Serial.print("\"\r");
  71.     delay(100);
  72.     gsm_SIM900A_Serial.print(message);
  73.     delay(100);
  74.     gsm_SIM900A_Serial.print((char)26); // Send Ctrl+Z to indicate end of message
  75.     delay(100);
  76.     Serial.println("SMS Sent");
  77. }
  78.  
  79. void receiveSMS() {
  80.     if (gsm_SIM900A_Serial.available()) {
  81.         String response = gsm_SIM900A_Serial.readString();
  82.         Serial.println("Received: " + response);
  83.     }
  84. }
  85.  
  86. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement