Advertisement
safwan092

GSM Code Simple

Mar 13th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1.  
  2. #include <SoftwareSerial.h>
  3.  
  4. //SIM800L TX is connected to Arduino D7
  5. #define SIM800L_TX_PIN 7
  6.  
  7. //SIM800L RX is connected to Arduino D6
  8. #define SIM800L_RX_PIN 6
  9.  
  10. //Create software serial object to communicate with SIM800L
  11. SoftwareSerial serialSIM800L(SIM800L_TX_PIN, SIM800L_RX_PIN);
  12.  
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.   //Being serial communication witj Arduino and SIM800L
  17.   serialSIM800L.begin(9600);
  18.   delay(15000);
  19.   Serial.println("Setup Complete!");
  20.   //sendSMSon();
  21.   delay(10000);
  22.   sendSMSoff();
  23. }
  24.  
  25. void loop() {
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. void sendSMSon() {
  44.  
  45.   Serial.println("Sending Text...");
  46.   serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  47.   delay(100);
  48.   serialSIM800L.print("AT+CMGS=\"05----------\"\r");
  49.   delay(200);
  50.   serialSIM800L.print("Water Pump is ON   ");
  51.   serialSIM800L.print("Sensor Value:");
  52.   serialSIM800L.print(15);
  53.   serialSIM800L.print(" , Moisture:");
  54.   serialSIM800L.print(15);
  55.   serialSIM800L.print("%");
  56.   serialSIM800L.print("\r"); //the content of the message
  57.   delay(500);
  58.   serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  59.   delay(100);
  60.   serialSIM800L.println();
  61.   Serial.println("Text Sent.");
  62.   delay(500);
  63.  
  64. }
  65.  
  66.  
  67. void sendSMSoff() {
  68.  
  69.   Serial.println("Sending Text...");
  70.   serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  71.   delay(100);
  72.   serialSIM800L.print("AT+CMGS=\"055---------\"\r");
  73.   delay(200);
  74.   serialSIM800L.print("Water Pump is OFF   ");
  75.   serialSIM800L.print("Sensor Value:");
  76.   serialSIM800L.print(100);
  77.   serialSIM800L.print(" , Moisture:");
  78.   serialSIM800L.print(100);
  79.   serialSIM800L.print("%");
  80.   serialSIM800L.print("\r"); //the content of the message
  81.   delay(500);
  82.   serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  83.   delay(100);
  84.   serialSIM800L.println();
  85.   Serial.println("Text Sent.");
  86.   delay(500);
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement