Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. //Create software serial object to communicate with SIM800L
  4. SoftwareSerial mySerial(10, 11); //SIM800L Tx & Rx is connected to Arduino #3 & #2
  5.  
  6. void setup()
  7. {
  8. //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  9. Serial.begin(9600);
  10.  
  11. //Begin serial communication with Arduino and SIM800L
  12. mySerial.begin(9600);
  13.  
  14. Serial.println("Initializing...");
  15. delay(1000);
  16.  
  17. mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  18. updateSerial();
  19.  
  20. mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  21. updateSerial();
  22. mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  23. updateSerial();
  24. }
  25.  
  26. void loop()
  27. {
  28. updateSerial();
  29. }
  30.  
  31. void updateSerial()
  32. {
  33. delay(500);
  34. while (Serial.available())
  35. {
  36. mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  37. }
  38. while(mySerial.available())
  39. {
  40. Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement