Advertisement
safwan092

GSM-SIM800LV2.2 + ARDUINO UNO + STC

May 17th, 2017
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. //SIM800L TX is connected to Arduino D3
  4. #define SIM800L_TX_PIN 7
  5.  
  6. //SIM800L RX is connected to Arduino D2
  7. #define SIM800L_RX_PIN 6
  8.  
  9. //Create software serial object to communicate with SIM800L
  10. SoftwareSerial serialSIM800L(SIM800L_TX_PIN, SIM800L_RX_PIN);
  11.  
  12. void setup() {
  13.   //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
  14.   Serial.begin(9600);
  15.   while (!Serial);
  16.  
  17.   //Being serial communication witj Arduino and SIM800L
  18.   serialSIM800L.begin(9600);
  19.   delay(1000);
  20.   Serial.println("Setup Complete!");
  21.  
  22.   delay(15000);
  23.   Serial.println("Sending Text...");
  24.   serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  25.   delay(100);
  26.  
  27.   serialSIM800L.print("AT+CMGS=\"0551234567\"\r");
  28.   delay(200);
  29.  
  30.   serialSIM800L.print("This is a message from DAWAER's Arduino!");
  31.   serialSIM800L.print("\r"); //the content of the message
  32.   delay(500);
  33.  
  34.   serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  35.   delay(100);
  36.  
  37.   serialSIM800L.println();
  38.  
  39.   Serial.println("Text Sent.");
  40.   delay(500);
  41.  
  42.  
  43. }
  44.  
  45. void loop() {
  46.   //Read SIM800L output (if available) and print it in Arduino IDE Serial Monitor
  47.   if (serialSIM800L.available()) {
  48.     Serial.write(serialSIM800L.read());
  49.   }
  50.   //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800L
  51.   if (Serial.available()) {
  52.     serialSIM800L.write(Serial.read());
  53.   }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement