Band Management
Manage the band the GSM shield connects to.
This example is part of the tools supplied to manage the GSM shield and shows how to use the GSM Library to manage the GSM band the modem connects to.
Check http://www.worldtimezone.com/gsm.html for general GSM band information. Typical regional configurations are:
- Europe, Africa, Middle East: E-GSM(900)+DCS(1800) 
- USA, Canada, South America: GSM(850)+PCS(1900) 
- Mexico: PCS(1900) 
- Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900) 
Hardware Required
- Arduino Board 
- SIM card 
Circuit
 
  
    
    
Code
1This sketch, for the Arduino GSM shield, checks the band  currently configured in the modem and allows you to change2it.1/*2
3 Band Management4
5 This sketch, for the Arduino GSM shield, checks the band6
7 currently configured in the modem and allows you to change8
9 it.10
11 Please check http://www.worldtimezone.com/gsm.html12
13 Usual configurations:14
15 Europe, Africa, Middle East: E-GSM(900)+DCS(1800)16
17 USA, Canada, South America: GSM(850)+PCS(1900)18
19 Mexico: PCS(1900)20
21 Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)22
23 Circuit:24
25 * GSM shield26
27 created 12 June 201228
29 by Javier Zorzano, Scott Fitzgerald30
31 This example is in the public domain.32
33 */34
35// libraries36#include <GSM.h>37
38// initialize the library instance39
40GSMBand band;41
42void setup() {43
44  // initialize serial communications and wait for port to open:45
46  Serial.begin(9600);47
48  while (!Serial) {49
50    ; // wait for serial port to connect. Needed for Leonardo only51
52  }53
54  // Beginning the band manager restarts the modem55
56  Serial.println("Restarting modem...");57
58  band.begin();59
60  Serial.println("Modem restarted.");61
62};63
64void loop() {65
66  // Get current band67
68  String bandName = band.getBand(); // Get and print band name69
70  Serial.print("Current band:");71
72  Serial.println(bandName);73
74  Serial.println("Want to change the band you're on?");75
76  String newBandName;77
78  newBandName = askUser();79
80  // Tell the user what we are about to do...81
82  Serial.print("\nConfiguring band ");83
84  Serial.println(newBandName);85
86  // Change the band87
88  bool operationSuccess;89
90  operationSuccess = band.setBand(newBandName);91
92  // Tell the user if the operation was OK93
94  if (operationSuccess) {95
96    Serial.println("Success");97
98  } else {99
100    Serial.println("Error while changing band");101
102  }103
104  if (operationSuccess) {105
106    while (true);107
108  }109}110
111// This function offers the user different options112// through the Serial interface113// The user selects one114
115String askUser() {116
117  String newBand;118
119  Serial.println("Select band:");120
121  // Print the different options122
123  Serial.println("1 : E-GSM(900)");124
125  Serial.println("2 : DCS(1800)");126
127  Serial.println("3 : PCS(1900)");128
129  Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe");130
131  Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am.");132
133  Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)");134
135  // Empty the incoming buffer136
137  while (Serial.available()) {138
139    Serial.read();140
141  }142
143  // Wait for an answer, just look at the first character144
145  while (!Serial.available());146
147  char c = Serial.read();148
149  if (c == '1') {150
151    newBand = GSM_MODE_EGSM;152
153  } else if (c == '2') {154
155    newBand = GSM_MODE_DCS;156
157  } else if (c == '3') {158
159    newBand = GSM_MODE_PCS;160
161  } else if (c == '4') {162
163    newBand = GSM_MODE_EGSM_DCS;164
165  } else if (c == '5') {166
167    newBand = GSM_MODE_GSM850_PCS;168
169  } else if (c == '6') {170
171    newBand = GSM_MODE_GSM850_EGSM_DCS_PCS;172
173  } else {174
175    newBand = "GSM_MODE_UNDEFINED";176
177  }178
179  return newBand;180}Last revision 2018/08/23 by SM
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.