Introduction: Arduino Cellular Shield Tutorial

About: My name is Randy and I am a Community Manager in these here parts. In a previous life I had founded and run the Instructables Design Studio (RIP) @ Autodesk's Pier 9 Technology Center. I'm also the author of t…

The Arduino Cellular Shield allows you to make cellular telephone calls, and send text messages. The brains of this shield is the SM5100B which is a robust cellular module capable of performing many of the tasks of most standard cell phones. This shield requires use of a SIM card to connect to a cellular network. The tutorial that follows is a bare bones tutorial for initializing the shield, and both sending and receiving text messages, and telephone calls. To learn more about the module's functionality, be sure to check out the datasheets on Sparkfun's product page.

Step 1: Go Get Stuff

You will need:

(x1) Cellular shield
(x1) Stackable Arduino headers
(x1) Quad band antenna
(x1) Arduino Uno

(Note that some of the links on this page are affiliate links. This does not change the cost of the item for you. I reinvest whatever proceeds I receive into making new projects. If you would like any suggestions for alternative suppliers, please let me know.)

Step 2: Solder Headers

Insert the headers into the shield and solder them into place.

Step 3: Insert

Insert the header pins into the sockets on the Arduino.

Step 4: Resolder

The antenna cable's connection to the SM5100B module is usually not very good. Resolder each of the cable's connections to the module to ensure connectivity.

Step 5: Attach the Antenna

Thread the antenna to the antenna cable.

Step 6: Insert SIM Card

Insert the SIM card securely into the SIM card socket.

Step 7: Initialize

Run the following code on the Arduino:

Open the serial port in the terminal. On a Mac this is accomplished by typing:
screen /dev/tty.usbmodemfa131 9600

(replace tty.usbmodemfa131 with your Arduino's serial address)


Wait to see the following sequence returned:

Starting SM5100B Communication...

+SIND: 3

+SIND: 4

+SIND: 11

(If this sequence is not returned check the error codes listed at the bottom of the code above, and debug appropriately. You may need to set the module for North American usage -- see below -- before it registers to network (i.e. +SIND 11))

Send the following commands to the serial port:

Send this for North American usage:
AT+SBAND=7

Set the current time - yy/mm/dd:
AT+CCLK="13/05/15,11:02:00"

Send test call:
ATD4155551212

Step 8: Text Messages

Download and install SerialGSM into your Arduino library.

To send a text message visit the Tronixstuff cellular module tutorial and use example code 26.3:
http://tronixstuff.wordpress.com/2011/01/19/tutorial-arduino-and-gsm-cellular-part-one/

If you would like to run the example code to receive a text, connect an LED to pin 8 and put it in series with a 220 ohm resistor to ground.

To send a text message visit the Tronixstuff cellular module tutorial and use example code 26.5:
http://tronixstuff.wordpress.com/2011/01/19/tutorial-arduino-and-gsm-cellular-part-one/

Text one of the following commands to your cellular module:

//turns the LED on
#a1

//turns the LED off
#a0

Step 9: Voice

Connect a microphone and speaker to the shield using grounded audio cable. The center signal wire should go to the audio plus terminals and the shielding should go to the respective negative terminals on the shield. These cables should be connected similarly on the microphone and speaker side.

To initialize a voice call upload the following code:
<pre>//**********************************************************************************
// MAKE A CALL
//
// BUFFERING CODE BASED UPON:
// <a href="http://jayeshprojects.blogspot.com/2010/04/real-time-mobile-gps-tracker-with.html">  http://jayeshprojects.blogspot.com/2010/04/real-t...>
//
//**********************************************************************************

#include <SoftwareSerial.h>
#define BUFFSIZ 90

//Set up buffer array
char at_buffer[BUFFSIZ];
char buffidx;

//Network state variables
int network_registered;
int network_AT_ready;

//Code state variables
int firstTimeInLoop = 1;
int firstTimeInOtherLoop = 1;
int x;
 
//Will hold the incoming character from the Serial Port.
char incoming_char=0;

//Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
SoftwareSerial cell(2,3);  


void setup() {
  
  //Initialize Arduino serial port for debugging.
  Serial.begin(9600);
  
  //Initialize virtual serial port to talk to Phone.
  cell.begin(9600);

  //Hello World.
  Serial.println("Starting SM5100B Communication...");
  delay(1000);

  //Set initial network state
  network_registered = 0;
  network_AT_ready = 0;

}


//Read AT strings from the cellular shield
void readATString(void) {

  char c;
  buffidx= 0; // start at begninning
  for (x = 0; x < 10000; x ++) {    
    if(cell.available() > 0) {
      c=cell.read();
      if (c == -1) {
        at_buffer[buffidx] = '\0';
        return;
      }
      if (c == '\n') {
        continue;
      }
      if ((buffidx == BUFFSIZ - 1) || (c == '\r')){
        at_buffer[buffidx] = '\0';
        return;
      }
      at_buffer[buffidx++]= c;
    }
  }
}




//Process the AT strings
void ProcessATString() {

  if( strstr(at_buffer, "+SIND: 8") != 0 ) {
    network_registered = 0;
    Serial.println("network Network Not Available");
  }

  if( strstr(at_buffer, "+SIND: 11") != 0 ) {
    network_registered=1;
    Serial.println("network Registered");
  }
  
  if( strstr(at_buffer, "+SIND: 4") != 0 ) {
    network_AT_ready=1;
    Serial.println("network AT Ready");
  }
}

 
void loop() {

/* If called for the first time, loop until network and AT is ready */

if(firstTimeInLoop == 1) {

  firstTimeInLoop = 0;
  while (network_registered == 0 || network_AT_ready == 0) {
    readATString();
    ProcessATString();
    }
  }

//LET'S MAKE A PHONE CALL!
if(firstTimeInOtherLoop == 1){
  
     //Change the 10 digit phone number to whatever you wish
     cell.println("ATD4155551212");
     firstTimeInOtherLoop = 0;
   }
}
To receive a voice call upload the following code:
<pre>//**********************************************************************************
// ANSWER A CALL
//
// BUFFERING CODE BASED UPON:
// <a href="http://jayeshprojects.blogspot.com/2010/04/real-time-mobile-gps-tracker-with.html">  http://jayeshprojects.blogspot.com/2010/04/real-t...>
//
//**********************************************************************************

#include <SoftwareSerial.h>
#define BUFFSIZ 90

//Set up buffer array
char at_buffer[BUFFSIZ];
char buffidx;

//Network state variables
int network_registered;
int network_AT_ready;

//Code state variables
int firstTimeInLoop = 1;
int firstTimeInOtherLoop = 1;
int x;
 
//Will hold the incoming character from the Serial Port.
char incoming_char=0;

//Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
SoftwareSerial cell(2,3);  


void setup() {
  
  //Initialize Arduino serial port for debugging.
  Serial.begin(9600);
  
  //Initialize virtual serial port to talk to Phone.
  cell.begin(9600);

  //Hello World.
  Serial.println("Starting SM5100B Communication...");
  delay(1000);

  //Set initial network state
  network_registered = 0;
  network_AT_ready = 0;

}


//Read AT strings from the cellular shield
void readATString(void) {

  char c;
  buffidx= 0; // start at begninning
  for (x = 0; x < 10000; x ++) {    
    if(cell.available() > 0) {
      c=cell.read();
      if (c == -1) {
        at_buffer[buffidx] = '\0';
        return;
      }
      if (c == '\n') {
        continue;
      }
      if ((buffidx == BUFFSIZ - 1) || (c == '\r')){
        at_buffer[buffidx] = '\0';
        return;
      }
      at_buffer[buffidx++]= c;
    }
  }
}




//Process the AT strings
void ProcessATString() {

  if( strstr(at_buffer, "+SIND: 8") != 0 ) {
    network_registered = 0;
    Serial.println("network Network Not Available");
  }

  if( strstr(at_buffer, "+SIND: 11") != 0 ) {
    network_registered=1;
    Serial.println("network Registered");
  }
  
  if( strstr(at_buffer, "+SIND: 4") != 0 ) {
    network_AT_ready=1;
    Serial.println("network AT Ready");
  }
}

 
void loop() {

/* If called for the first time, loop until network and AT is ready */

if(firstTimeInLoop == 1) {

  firstTimeInLoop = 0;
  while (network_registered == 0 || network_AT_ready == 0) {
    readATString();
    ProcessATString();
    }
  }

if(firstTimeInOtherLoop == 1){
  //Look for incoming call
  if( strstr(at_buffer, "+CPAS: 3") != 0 ) {
     //Answer the phone
     cell.println("ATA");
     firstTimeInOtherLoop = 0;
   }
 }
}

Did you find this useful, fun, or entertaining?
Follow @madeineuphoria to see my latest projects.

Epilog Challenge V

Participated in the
Epilog Challenge V

Pocket Sized Electronics

Participated in the
Pocket Sized Electronics