Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. // Makes a SoftwareSerial object in order to communicate with SIM800L module
  4. SoftwareSerial gsmSerial(12, 11); // SIM800L TXD and RXD is connected to the Arduino pins 12 and 11 respectively
  5.  
  6. void setup()
  7. {
  8.   // Starts the serial communication between the SIM800L module and the Arduino.
  9.   gsmSerial.begin(9600);
  10.  
  11.   // Starts the serial communication between the Arduino and serial monitor.
  12.   Serial.begin(9600);
  13.  
  14.   delay(100);
  15.   gsmSerial.println("AT"); // Handshake to check if the module is running. If returns OK, then its fine.
  16.  
  17. }
  18.  
  19. void loop()
  20. {
  21.   if (Serial.available() > 0)
  22.   switch(Serial.read())
  23.   {
  24.     case 's':
  25.       SendSMS();
  26.       break;
  27.     case 'r':
  28.       ReadSMS();
  29.       break;
  30.  
  31.   }
  32.  
  33.  if (gsmSerial.available() > 0) // if theres any data to collect from the GSM module
  34.    Serial.write(gsmSerial.read()); // then print it to the serial monitor
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement