ScienceGeyser

GSM_Test_Code

Jun 20th, 2021
726
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial sim800(10, 11); // gsm module connected here
  3. String textForSMS;
  4. const int buzzer = 9; //buzzer to arduino pin 9
  5. int data = 0;
  6. int sensor = A5; // water sensor is connected with the analog pin A5 of the Arduino
  7. // cell numbers to which you want to send the security alert message
  8. String f1001 = "+639214777242";
  9. String f1002 = "+639257795654";
  10. String f1003 = "+639498232922";
  11.  
  12.  
  13. void setup() {
  14.   pinMode(buzzer, OUTPUT);
  15.   Serial.begin(9600);
  16.   sim800.begin(9600); // original 19200. while enter 9600 for sim900A
  17.   Serial.println("SIM800L ACTIVATED!");
  18.   delay(5000); // wait for 5 seconds
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24. data = analogRead(sensor);
  25. Serial.println(data);
  26.  
  27.  
  28.      if ( data < 350) //
  29.   {
  30.    
  31.   //sendSMS(textForSMS);
  32.   sendsms("Water Detected! Please send this in our GC if you saw this message!", f1001); // you can use a variable of the type String
  33.   Serial.println("Hmmmm....");
  34.   Serial.println("message sent.");
  35. delay(5000);
  36.  
  37.   sendsms("Water Detected! Please send this in our GC if you saw this message!", f1002); // you can also write any message that you want to send.
  38.   Serial.println("Hmmmm.....");
  39.   Serial.println("message sent.");
  40. delay(5000);
  41.  
  42.   sendsms("Water Detected! Please send this in our GC if you saw this message!", f1003); // you can also write any message that you want to send.
  43.   Serial.println("Hmmmm....");
  44.   Serial.println("message sent.");
  45.   delay(5000);
  46.  
  47.   tone(buzzer, 1000);
  48.   delay(10000);  
  49.   noTone(buzzer);
  50.   }
  51. }
  52.  
  53.  
  54. void sendsms(String message, String number)
  55. {String mnumber = "AT + CMGS = \""+number+"\"";
  56.    sim800.print("AT+CMGF=1\r");                  
  57.   delay(1000);
  58.  sim800.println(mnumber);  // recipient's mobile number, in international format
  59.  
  60.   delay(1000);
  61.   sim800.println(message);                         // message to send
  62.   delay(1000);
  63.   sim800.println((char)26);                        // End AT command with a ^Z, ASCII code 26
  64.   delay(1000);
  65.   sim800.println();
  66.   delay(100);                                     // give module time to send SMS
  67.  // SIM900power();  
  68. }
RAW Paste Data