Advertisement
safwan092

Untitled

Dec 17th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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. sendSMSon();
  24. }
  25.  
  26. void loop() {
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. void sendSMSon() {
  45.  
  46. Serial.println("Sending Text...");
  47. serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  48. delay(100);
  49. serialSIM800L.print("AT+CMGS=\"0555541625\"\r");
  50. delay(200);
  51. serialSIM800L.print("text here ");
  52. serialSIM800L.print("Sensor Value:");
  53. serialSIM800L.print(15);
  54. serialSIM800L.print(" , Moisture:");
  55. serialSIM800L.print(15);
  56. serialSIM800L.print("%");
  57. serialSIM800L.print("\r"); //the content of the message
  58. delay(500);
  59. serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  60. delay(100);
  61. serialSIM800L.println();
  62. Serial.println("Text Sent.");
  63. delay(500);
  64.  
  65. }
  66.  
  67.  
  68. void sendSMSoff() {
  69.  
  70. Serial.println("Sending Text...");
  71. serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  72. delay(100);
  73. serialSIM800L.print("AT+CMGS=\"0555541625\"\r");
  74. delay(200);
  75. serialSIM800L.print("Water Pump is OFF ");
  76. serialSIM800L.print("Sensor Value:");
  77. serialSIM800L.print(100);
  78. serialSIM800L.print(" , Moisture:");
  79. serialSIM800L.print(100);
  80. serialSIM800L.print("%");
  81. serialSIM800L.print("\r"); //the content of the message
  82. delay(500);
  83. serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  84. delay(100);
  85. serialSIM800L.println();
  86. Serial.println("Text Sent.");
  87. delay(500);
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement