Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- SoftwareSerial sim800(10, 11); // gsm module connected here
- String textForSMS;
- const int buzzer = 9; //buzzer to arduino pin 9
- int data = 0;
- int sensor = A5; // water sensor is connected with the analog pin A5 of the Arduino
- // cell numbers to which you want to send the security alert message
- String f1001 = "+639214777242";
- String f1002 = "+639257795654";
- String f1003 = "+639498232922";
- void setup() {
- pinMode(buzzer, OUTPUT);
- Serial.begin(9600);
- sim800.begin(9600); // original 19200. while enter 9600 for sim900A
- Serial.println("SIM800L ACTIVATED!");
- delay(5000); // wait for 5 seconds
- }
- void loop() {
- data = analogRead(sensor);
- Serial.println(data);
- if ( data < 350) //
- {
- //sendSMS(textForSMS);
- sendsms("Water Detected! Please send this in our GC if you saw this message!", f1001); // you can use a variable of the type String
- Serial.println("Hmmmm....");
- Serial.println("message sent.");
- delay(5000);
- 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.
- Serial.println("Hmmmm.....");
- Serial.println("message sent.");
- delay(5000);
- 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.
- Serial.println("Hmmmm....");
- Serial.println("message sent.");
- delay(5000);
- tone(buzzer, 1000);
- delay(10000);
- noTone(buzzer);
- }
- }
- void sendsms(String message, String number)
- {String mnumber = "AT + CMGS = \""+number+"\"";
- sim800.print("AT+CMGF=1\r");
- delay(1000);
- sim800.println(mnumber); // recipient's mobile number, in international format
- delay(1000);
- sim800.println(message); // message to send
- delay(1000);
- sim800.println((char)26); // End AT command with a ^Z, ASCII code 26
- delay(1000);
- sim800.println();
- delay(100); // give module time to send SMS
- // SIM900power();
- }
Advertisement
Add Comment
Please, Sign In to add comment