Simple example to get confidence ith a GSM Shield or Module


 A simple GSM test forMega
 The idea is to check that the Modem is connected correctly syncs with tower and is active on cell network
   Requirements a Serial Monitor on USB port 
 * Any serial device attached to Serial port 0 the USB I favour CoolTerm a simple Terminal Emulator
 * A GSM modem connected to Serial port  1 , 2 or 3
  Important GSM modoms are configured as DCE devices

  = So TX on modem connects to the Serial port RX
  =    Rx is connected to TX
 Don't forget to join GNDS together.
 A so called cross connection cable 

 created April 2014

 This example code is in the public domain.


void setup() {
  // initialize both serial ports:
  Serial3.begin(9600);  // using Serial 3 because my test rig is wired that way.. 

void loop() 
  // read from port 0, send to port 3
  if (Serial.available()) 
    char inByte =;
    Serial.print(inByte);   // local echo so you see what you are typing
  // read from port 3, send to port 0
  if (Serial3.available())
    char inByte =;

Basically once downloaded, you can send any AT commands and get responses.

Suggest the following sequence. AT . . should get an echo + OK

ATE0 .. turns off echo should get OK

AT+COPS? Reply tell you SIM registration status and with which carrier AT+CREG? Reply indicates manner of SIM registration i.e Roaming, international etc.

AT+CSQ Reply indicates signal quality on cell network

AT+CMGF = 1 Sets text mode on SMS AT+CMGL=ALL Reply shows all SMS's in Memory and Status

Sending SMS

AT+CMGS = "+XXX.. Phone Number must be in 13 digit International format You must wait for the > reply ![/b Then send SMS max 160 characters including a Cntrl Z terminator What you will gain by playing with this simple idea is: The synchronisation timing needed delays do not really hack it, if the cell circuits are busy response to the CMGS command can be up to 15 seconds and still conform to the cell network ISO specs. Late at night when not a lot of traffic response can be in milliSeconds Its really not feasible to code without looking at responces and decoding to ensure you stay in sync Most modems I have tested either reset if you send another command or data when they do not expect it, For example the Siemans TC35/35i module are cheap, they work perfectly if you obey synchronisation rules I have several in systems that are active 24/7 but they can totally Lock if you do something wrong i.e break the sync sequence, and will only recover with a power down!

I have looked at the various available library code in detail, the libraries seem geared to specific shields hence to specific hardware this is only to be expected, so beware if you use a shield without a dedicated library, but the chinese copy shields and modules have very poor software support. I hope this will help some of you..