Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. /*
  2. SMS receiver
  3.  
  4. This sketch, for the Arduino GSM shield, waits for a SMS message
  5. and displays it through the Serial port.
  6.  
  7. Circuit:
  8. * GSM shield attached to and Arduino
  9. * SIM card that can receive SMS messages
  10.  
  11. created 25 Feb 2012
  12. by Javier Zorzano / TD
  13.  
  14. This example is in the public domain.
  15.  
  16. http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
  17.  
  18. */
  19.  
  20. // include the GSM library
  21. #include <GSM.h>
  22.  
  23. // PIN Number for the SIM
  24. #define PINNUMBER ""
  25.  
  26. // initialize the library instances
  27. GSM gsmAccess;
  28. GSM_SMS sms;
  29.  
  30. // Array to hold the number a SMS is retreived from
  31. char senderNumber[20];
  32.  
  33. void setup() {
  34. // initialize serial communications and wait for port to open:
  35. Serial.begin(9600);
  36. while (!Serial) {
  37. ; // wait for serial port to connect. Needed for Leonardo only
  38. }
  39.  
  40. Serial.println("SMS Messages Receiver");
  41.  
  42. // connection state
  43. boolean notConnected = true;
  44.  
  45. // Start GSM connection
  46. while (notConnected) {
  47. if (gsmAccess.begin(PINNUMBER) == GSM_READY)
  48. notConnected = false;
  49. else {
  50. Serial.println("Not connected");
  51. delay(1000);
  52. }
  53. }
  54.  
  55. Serial.println("GSM initialized");
  56. Serial.println("Waiting for messages");
  57. }
  58.  
  59. void loop() {
  60. char c;
  61.  
  62. // If there are any SMSs available()
  63. if (sms.available()) {
  64. Serial.println("Message received from:");
  65. // Get remote number
  66. sms.remoteNumber(senderNumber, 20);
  67. Serial.println(senderNumber);
  68. // An example of message disposal
  69. // Any messages starting with # should be discarded
  70. if (sms.peek() == '#') {
  71. Serial.println("Discarded SMS");
  72. sms.flush();
  73. }
  74.  
  75. // Read message bytes and print them
  76. while (c = sms.read())
  77. Serial.print(c);
  78. Serial.println("nEND OF MESSAGE");
  79.  
  80. // Delete message from modem memory
  81. sms.flush();
  82. Serial.println("MESSAGE DELETED");
  83. }
  84. delay(1000);
  85. }
  86.  
  87. if (gsmAccess.begin(PINNUMBER) == GSM_READY)
  88.  
  89. GSMBand band;
  90. String newBand= "GSM_MODE_EGSM_DCS";// Your Band In My case That was
  91. band.begin();
  92. Serial.println("Modem restarted.");
  93. String bandName = band.getBand(); // Get and print band name
  94. Serial.print("Current band:");
  95. Serial.println(bandName);
  96.  
  97. band.setBand(newBand);
  98.  
  99. GSM_MODE_EGSM ---- E-GSM(900)
  100. GSM_MODE_DCS ---- DCS(1800)
  101. GSM_MODE_PCS ---- PCS(1900)
  102. GSM_MODE_EGSM_DCS ---- E-GSM(900)+DCS(1800) ex: Europe
  103. GSM_MODE_GSM850_PCS ---- GSM(850)+PCS(1900) Ex: USA, South Am.
  104. GSM_MODE_GSM850_EGSM_DCS_PCS ---- GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)
  105.  
  106. gsm.access.begin();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement