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: **SMS Module**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-05 22:28:25
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Develop a project utilizing the SIM900 GSM module */
- /* for sending and receiving SMS messages. Ensure the */
- /* SoftwareSerial interface on A0 and A1 is */
- /* configured for seamless communication and */
- /* implement basic command responses. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- #include <sim900.h> //https://github.com/nthnn
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void sendSMS(const char* number, const char* message);
- void receiveSMS();
- /***** DEFINITION OF Software Serial *****/
- const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_TX_A0 = A0;
- const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_RX_A1 = A1;
- SoftwareSerial gsm_SIM900A_Serial(gsm_SIM900A_Serial_PIN_SERIAL_RX_A1, gsm_SIM900A_Serial_PIN_SERIAL_TX_A0);
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // Initialize GSM module communication
- gsm_SIM900A_Serial.begin(9600);
- Serial.begin(9600); // Initialize serial monitor communication
- Serial.println("GSM Module Ready");
- }
- void loop(void)
- {
- // Example of sending an SMS
- sendSMS("+1234567890", "Hello from Arduino!");
- // Check for incoming SMS
- receiveSMS();
- delay(10000); // Wait for 10 seconds before sending another SMS
- }
- void sendSMS(const char* number, const char* message) {
- gsm_SIM900A_Serial.print("AT+CMGF=1\r"); // Set SMS to text mode
- delay(100);
- gsm_SIM900A_Serial.print("AT+CMGS=\"");
- gsm_SIM900A_Serial.print(number);
- gsm_SIM900A_Serial.print("\"\r");
- delay(100);
- gsm_SIM900A_Serial.print(message);
- delay(100);
- gsm_SIM900A_Serial.print((char)26); // Send Ctrl+Z to indicate end of message
- delay(100);
- Serial.println("SMS Sent");
- }
- void receiveSMS() {
- if (gsm_SIM900A_Serial.available()) {
- String response = gsm_SIM900A_Serial.readString();
- Serial.println("Received: " + response);
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement