SM5100B GPRS and General Notes





Introduction: SM5100B GPRS and General Notes

This instructable is for the use of the SM5100B-D shield from sparkfun:
Its no good to you for the other GSM shields, Sorry.

I spent so, so long hacking at this stupid shield trying to make sense of the +SIND's  and other rubbish - these things do work, they just test your patience. The minimal and poorly written documentation is useful if not as frustrating, hopefully this will save you some time.

Dont take this all for gospel, Im not an electronics or programming whizz, I have just persevered and learnt a few things.
Please feel free to question anything written here and Ill try to update the instruct-able if you can contribute.

Step 1: Things to Consider

I have found some good resources,
The most useful being some actual working code:
A good intro into setup

Some things to note:
1) Software serial is not the best option, in my tests it doesn't keep up with the serial output from the GSM module, and if you cant keep up then the data is dropped and your stuck. Software serial is ok for grabbing the return codes from your AT commands but when it comes to receiving your actual data, like http responses - it just doesn't keep up at all. I have seen mention that the 9600 baud rate that the SM5100B-D is set to is not fast enough, I have not found this to be true, as long as I use a hardware UART I get all the data back from the shield.

2) Power - you cant run this shield from the Arduino Power - you just cant. I tried to ignore these warnings, dont waste your time. Feed it 5 volts from a transformer or battery capable of supplying 2-3 amps. You will find that if you dont it will just keep overdrawing on your Arduino when it goes to transmit and everything will just reset.

3) Antenna, you need one.
I have actually been able to get +SIND:4 without one, but I have been getting full reception with one of those tiny little duck Antennas - I got two for a couple of dollars right here: For Australians - You can pick up an antenna from Jaycar - pricey but dont have to wait on delivery:

4) Documentation, the official AT command set documentation comes in handy, only the author truly knows what on earth he/she was trying to describe, its bad, real bad, but it comes in handy:
I guess sparkfun wrote this more specific GPRS / IP stuff, as it kind of makes sense in comparison:

Step 2: Power

As mentioned, you need external power. Im using a 3 amp 5 volt regulated power supply. Negative into GND and positive into VIN. Picture 1

Step 3: Serial Connections

As mentioned, I have had no luck using the software serial library to talk to the SM5100B-D.
Since you need to use a Hardware UART for the GSM stuff, and you need to use a serial connection also for your debugging purposes, you need either more hardware UARTS or A USB serial adaptor.

So the options are:

1) Get a Mega 2560 - official from Arduino:
Or I prefer the free tronics EtherMega:
These Arduinos have 4 hardware UARTS, plenty!

2) Use your standard UNO or whatever and also make use of a USB serial adaptor such as the one I have from freetronics: or one of the prolific based usb serial converters that are all over ebay. (If using the ebay jobbies - check that they are 5 volt logic not 12v, 12v will fry arduino!)

I'm using option 2, usb Serial Adaptor.
With RX and TX going to pins 2 and 3 on my uno. Vout & Gnd to the Uno's Gnd and Vin.
Conveniently this Serial adaptor will power the uno as well, if your using a standard serial converter cable like the prolific ones you'll need an external 5 volt source for your arduino, you can take it from the SM5100B-D 5v and GND.

From the SM5100B-D i have pins 2 and 3 connected to the Hardware UART on the UNO pins 0 and 1.
You can see I have not stacked the GSM board ontop of the UNO!
This is because when I need to upload sketches to the UNO it cannot be done through the software serial pins that and the USB serial adaptor. I have to disconnect the SM5100B-D serial connection and plug the USB cable into the uno to upload the sketch. The Arduinos will only accept sketches uploaded to pins 0/1!

And I have to remember to disconnect the SM5100B-D from these pins while uploading code it will not know what to do with that info being dropped on pins 0/1 during this time, it might also be dangerous for one or the other board? Either way when uploading code disconnect the serial connection between the uno and SM5100B-D and then reconnect again.

So the first photo is the connection when I am running my GPRS code and debugging, with the software serial port sending data out pins 2/3 to the USB serial adaptor to the serial monitor, and the hardware UART pins 0/1 doing the high speed communication with the SM5100B-D.
The second photo is what I have to do for uploading sketches.

Yes It would be easier to just use a MEGA 2560!

Step 4: +SIND 4

We need to see a +SIND: 4 response from the SMB5100B-D, ( im just gonna call that the GSM card now, sick of typing SMB5100B-D).

So some easy code for checking this:

#define GSMSerial Serial // the hardware serial will now be known as GSMSerial, to avoid confusion
SoftwareSerial SMSerial(2,3); //Using Software Serial as second UART -
char incoming_char=0; //Will hold the incoming character from the software Serial Port.
void setup()
//Initialize serial ports for communication.
SMSerial.println("Starting SM5100B Communication...");
void loop()
if(GSMSerial.available()>0) //If a character comes in from the cellular module...
SMSerial.write(; //write it out to the serial monitor so we can see it
if(SMSerial.available() >0) //If you type something into the serial monitor
{; //Get the character coming from the terminal
GSMSerial.print(incoming_char); //Send the character to the cellular module.

You should see the following output on your serial monitor:

Starting SM5100B Communication...
+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+SIND: 11
+SIND: 3
+SIND: 4

If you get nothing, you probably mixed up the TX RX pins on the serial monitor.

If you get "Starting SM5100B Communication..." then a whole lot of gobbly gook then you may have mixed up the serial TX RX pins between uno 0/1 and GSM 2/3

If its all just rubbish output then check if your serial monitor is set to 9600!

BUT If the last line you got was "+SIND: 4" then your luckier than most:)
If you got anything else as the last line, you need to find out why. You'll get more info on that here.

+SIND: 4 means we are registered on the mobile network and ready to do stuff.
For Example, type into the serial monitor, ATDXXXXXXXXXX
With the X's replaced with your own mobile number, and hit enter. (Make sure NL & CR are selected in the drop-down box at the bottom of the serial monitor). The sketch you uploaded will pass this to your GSM module and it will dial your mobile. You can send the command ATH to hangup.

Step 5: GPRS

If you got this far and you can either send an SMS or make a call, or some other way validate that you indeed have a functioning connection to the mobile network then we can try to get a GPRS session going.

This code is a hacked up from a sample I found by a guy named Toby: it was pretty much the only functioning bit of code on the internet! Thank You Toby Fox!!
It calls out to and makes a http get request. is a handy set of pages for debugging http stuff.

You may want to just go and grab Toby's sample instead cause its the original, probrably better and is well documented, although this one below is already modified to use the Hardware UART for GSM and software for serial monitor as mentioned earlier.

// Using the Hardware UART Initially to program the Sketch,
// Disconnect the GSM serial connection, plug usb into uno and upload sketch.
//Then to test the sketch, then remove the usb from uno and plug into the USB-Serial module.
// plug the GSM modem serial wires back into the hardware UART pins 0&1 again

//The idea is to use the GSM modem with the hardware UART as the Software Serial Library
//is to slow for GSM modem, but its obviously fine for debugging stuff

#define GSMSerial Serial
SoftwareSerial SMSerial(2,3); //Using Software Serial as second UART -
const String apn = "internet"; // access-point name for GPRS
const String ip = ""; // IP address of server we're connecting to
const String host = ""; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String request = "GET /get?data=testing HTTP/1.1";
const String useragent = "Mozilla/5.0"; // for our purposes the user agent doesn't matter - if I understand correctly it's helpful to use something generic the server will recognize
void setup()
SMSerial.println("Starting SM5100B Communication...");
waitTil("+SIND: 4"); // keep printing GSMSerial output til we get "+SIND: 4"
SMSerial.println("Module ready");
void loop()

SMSerial.println("Attaching GPRS...");
SMSerial.println("Setting up PDP Context...");
SMSerial.println("Activating PDP Context...");
SMSerial.println("Configuring TCP connection to TCP Server...");
SMSerial.println("Starting TCP Connection...");
while (1) { // now we'll loop forever, checking the socket status and only breaking when we connect
SMSerial.println("Checking socket status:");
GSMSerial.println("AT+SDATASTATUS=1"); // we'll get back SOCKSTATUS and then OK
String sockstat = getMessage();
if (sockstat=="+SOCKSTATUS: 1,0,0104,0,0,0") {
//SMSerial.println("Not connected yet. Waiting 1 second and trying again.");
else if (sockstat=="+SOCKSTATUS: 1,1,0102,0,0,0") {
SMSerial.print(" !!!Socket connected!!! ");
else {
SMSerial.println("We didn't expect that.");
int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
SMSerial.println("Sending HTTP packet...");
waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
GSMSerial.print(request+"\r\n"); // SIZE: 2
GSMSerial.print("Host: "+host+"\r\n"); // SIZE: 8
GSMSerial.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
GSMSerial.write(26); // ctrl+z character: send the packet
waitTil("+STCPD:1"); // this means data is received
//waitTil("+STCPC:1"); // this means socket is closed
SMSerial.println("Reading data from server...");
GSMSerial.println("AT+SDATAREAD=1"); // how we read data server has sent
cellOutputForever(); // just keep printing whatever GSM module is telling us
* what is +STIN:1 ?
* to disconnect after transmission: AT+CGACT=0,1 breaks socket. AT+CGATT=0 seems to work more authoritatively?
* AT+SDATASTART=1,0 // close TCP connection
* AT+SDATASTATUS=1 // clear sent/ack bytes from SOCKSTATUS
// ====== HELPER FUNCTIONS ====== //
// keep reading the serial messages we receive from the module
// loop forever until we get a nonzero string ending in \r\n - print and return that.
// TODO: implement a timeout that returns 0?
String getMessage() {
String s="";
while(1) {
if(GSMSerial.available()>0) {
s = s+(char);
if (s.length()>1 && s[s.length()-2]=='\r' && s[s.length()-1]=='\n') { // if last 2 chars are \r\n
if (s==" \r\n" || s=="\r\n") { // skip these, move on
else { // we have a message!
return s.substring(0,s.length()-2);
// for eating a single message we expect from the module
// prints out the next message from the module. if it's not the expected value, die
void waitFor(String s) {
String message=getMessage();
if (message != s) {
SMSerial.println("Wait, that's not what we were expecting. We wanted \""+s+"\"");
delay(100); // wait for a tiny bit before sending the next command
// keep spitting out messages from the module til we get the one we expect
void waitTil(String s) {
String message;
while (1) {
message = getMessage();
if (message == s){
delay(100); // cause we're probably about to send another command
// keep reading characters until we get char c
void waitFor(char c) {
while(1) {
if(GSMSerial.available()>0) {
if ((char) == c) {
// if something goes wrong, abort and just display cell module output so we can see error messages
// this will loop forever
void cellOutputForever() {
SMSerial.println("Now displaying cell module output forever");
char incoming_char=0;
if(SMSerial.available() >0)
{; //Get the character coming from the terminal
GSMSerial.print(incoming_char); //Send the character to the cellular module.
// like above, but in hex, useful for debugging
void cellHexForever() {
while(1) {
if(GSMSerial.available()>0) {
char c = (char);
// Serial.print("a char: ");
SMSerial.print(c, HEX);
SMSerial.print(" ");
// receive string such as "SOCKSTATUS: 1,1,0102,10,10,0"
// 0 is connection id. 1 is whether connected or not. 2 is status (0104 is connecting, 0102 is connected, others)
// 3 is sent bytes. 4 is acknowledged bytes. 5 is "received data counter"
// THIS FUNCTION WILL check that sent bytes == ack bytes, and return that value
// return 0 if they don't match or if amount of data is 0
int checkSocketString(String s) {
if (socketStringSlice(3,s) == 0)
return 0;
else if (socketStringSlice(3,s) == socketStringSlice(4,s))
return socketStringSlice(3,s);
return 0;
// returns the index of the nth instance of char c in String s
int nthIndexOf(int n, char c, String s) {
int index=0;
for (int i=0; i<=n; i++) {
index = s.indexOf(c,index+1);
return index;
// expects string such as "SOCKSTATUS: 1,1,0102,10,10,0"
// returns nth chunk of data, delimited by commas
int socketStringSlice(int n, String s) {
String slice = s.substring(nthIndexOf(n-1,',',s)+1,nthIndexOf(n,',',s));
char cArray[slice.length()+1];
slice.toCharArray(cArray, sizeof(cArray));
return atoi(cArray);

Here is the Serial monitor output you should expect
Starting SM5100B Communication...
+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+SIND: 11
+SIND: 3
+SIND: 4
Module ready
Attaching GPRS...
Setting up PDP Context...
Activating PDP Context...
Configuring TCP connection to TCP Server...
Starting TCP Connection...
Checking socket status:
+SOCKSTATUS: 1,0,0104,0,0,0
Checking socket status:
+SOCKSTATUS: 1,1,0102,0,0,0
!!!Socket connected!!! Sending HTTP packet...
Reading data from server...
Now displaying cell module output forever

Note that the +SDATA output is in HEX, so that big old string of garble you will receive back needs to be converted.
You can paste it into this site to get an easy look at what the output was:
and after decoding the hex, our output is

HTTP/1.1 200 OK??Access-Control-Allow-Origin: *??Content-Type: application/json??Date: Thu, 14 Nov 2013 05:27:23 GMT??Server: gunicorn/0.17.4??Content-Length: 263??X-Cache: MISS from tx22rrpep23b??Connection: keep-alive????{? "url": "",? "headers": {? "Connection": "close",? "Host": "",? "Cache-Control": "max-age=259200",? "User-Agent": "Mozilla/5.0"? },? "origin": "",? "args": {? "data": "testing"? }?}?

So a successfull http get request, I never thought it would happen.


You can tell the 5100B to replay you the recived data in ASCII!! With one simple command "AT+SDATARXMD=1,1,0"

So before this line:"GSMSerial.println("AT+SDATAREAD=1"); // how we read data server has sent"
add the code:


This will set the output to ASCII just before you call the SDATAREAD!
And the data your presented will now look much more beautiful more like this:

+SSTR:1,HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cont12:16 GMT
Server: gunicorn/0.17.4
Content-Length: 264
X-Cache: MISS from tx22rrpep38a
Connection: keep-alive
"args": {
"data": "testing"
"headers": {
"Host": "",
"User-Agent": "Mozilla/5.0",
"Cache-Control": "max-age=259200",
"Connection": "close"
"url": "",
"origin": ""

With no need for you to write a Hex to ASCII conversion function:)

One big old problem this presents is the "OK" that is part of a HTTP response.
OK is also the way the SM5100B tells us its processed a command, whenever we se "OK\r\n" as a string in the serial buffer we know that the GSM module has answered and this forms the end of the message,,, so then its difficult to know if the "OK\r\n" at the beginning of the HTTP response is part of the response or the message at the end of successfully processing the AT Command.  
"So look for the second "OK\r\n" I thought... but then what if there is also a "OK\r\n" in the body of the response!!! 
Any ideas anyone, bueller, anyone?

Step 6: Make an Arduino Library

So now I am working on a library so that I can make simple http requests without having to deal with all of that code.
I hope to make it as simple as response = GSMhttpGet("URL").
Anyone want to help with this?

Im making allot of progress with this library already.
Here are the functions I have already got coded and partially tested:

void reboot();
String GetReceptionLvl();
int hasNetworkReg();
int networkSignal();
void placeCall(String phoneNumber);
void hangUp();
void answerCall();
void sendDTMF(String DTMFTone);
void setDTMFTime(String DtmfTime);
void sendSMS(String sendTo, String sendText);
int getSMSMsgCount(String storeType); //Dont use: made obsolete by getSMSIndexs
void getSMSByIndex(int smsIndex, String smsString[]);
bool deleteSMSByIndex(int smsIndex);
void getSMSIndexs(int smsIndexs[], int &arraysize);
bool GPRSCheckAndAttach();
bool PDPSetupAndActivate(String apn);
bool TCPIPSetupAndStart(String IP);
String HttpGet(String Request, String host, String useragent);

Ive basically gone through the AT command documentation and made functions out of all the useful AT commands.
Then made some more goodies like, getmssagecount, and some GPRS functions, and HttpGet which accepts all the required information, makes the HTTP get and returns you back the result. Im not a C coder, Im a hack, so Im not going to post this library till Ive had the best go I can at it, if anyone wants it in its current state or would like to help me build on it, please send me a message!




  • LED Contest 2017

    LED Contest 2017
  • Raspberry Pi Contest 2017

    Raspberry Pi Contest 2017
  • Voice Activated Challenge

    Voice Activated Challenge

We have a be nice policy.
Please be positive and constructive.


Questions & Answers


I did and set up sms/call functions. I see all the sind commands, but after uploading this sketch I dont have any feedback in my serial monitor. No more sind, just messages from softwareserial pins. Did you have this issue?

Hey Thanks for all your info on this. I have successfully made connection to my web server. I'm no t a C coder either but I would love to look at your library and perhaps have a go at it with you. send me a message if you are interested


Sorry to say I dropped the ball on this.

I really needed a GSM modem in the end form my project so got a 3g dongle and connected it to a beaglebone, was allot of hassle trying to work with AT commands and strings and such when I really just needed full blown tcp routing.

I can dig up the code I had started for the library if your interested, its fairly basic but maybe its a starting point if you wish to pursue it? Library had some test scripts as well.

I've zipped them up and I PM'd you, reply if your interested in what I have so far and ill send it.


I am working on a project and your info has been really helpfull! Could you plz send me a copy of your arduino library?


G'day Cristobalgh, were are you from mate?

I don't have your email so I have put it up on dropbox:

I don't remember what state the library is but I assume its as i left it.

Im not a great coder so its probably just a good reference for you to make your own code more than a fantastic library ready to use;)




Can I please ask why did you need the USB serial adapter. Couldn't you connect to the one UART you have? I have Arduino Due with 4 UART and having trouble connecting it properly to the shield? How should it be connected as I get no response on the serial monitor.

Thank you

I was using a uno with only one UART, I needed that one UART for the module to talk to the arduino but also wanted to wanted to debug via the serial monitor which needs a UART as well so I needed the extra FTDI serial connection, you wont need it as you have 4 on board - I have since taken to the mega 2560 so I dont need that any longer either.

Are you getting no response at all from your aduino or the arduino is showing no response from the GSM module?

First Thank you.
On my cellular shield, the two connections that are soldered together are the two closest to the Rx Tx writing. According to the schematic and my understanding, this only enables the shield to send serial communication via ports 2,3. My connections:
Arduino Due connected to computer via USB.
Shield gets its power from 5v external power (capable of 2.5A) supply and both the shield and the board are connected to its ground.
Port 2 of shield connected to Tx1 of Arduino
Port 3 of shield connected to Rx1 of Arduino.
I have also tried to used ports 0,1 of the shield labelled Rx Tx and connect them to Arduino serial 1. Anyway still nothing appears on Arduino IDE serial monitor but starting serial communication.
Any help will be much appreciated...

And did you try the amended code I added in the comment below?

I think port two on the GSM module is TX and should go to the RX of your arduino - I know that looks strange as the markings show RX TX for 0 & 1 and so you would guess that it was RX TX for 2 & 3 - but no its TX RX for pins 2 & 3 on the GSM shield.

Try that simple swap first, then if no good - troubleshoot with some ideas below:

Connect TX0 to RX1, and RX0 to TX1 - then start the serial montitor

You should get the "Starting SM5100B Communication..." bouncing backwards and forwards between your serial connections and printing over and over on your serial monitor - If so your Code is working fine.

If so, then connect pin 2 of GSM Sheild (confusingly it seems pin two is TX not pin 3 as i would have guessed) to your Serial 1 RX and restart the shield and the arduino.

Also remember when your searching for the serial connection, restart the GSM sheild after making changes as it goes through its setup and then goes quiet, so you may not see anything and think its not working, but in reality its just waiting for you to talk to it - So reset gsm shield and see if you get any serial data.

If your not getting any serial data resembling

+SIND: 11

+SIND: 3

+SIND: 4


+SIND: 1

+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1


+SIND: 4

then at this point then you need to work out why your GSM shield is not communicating. Even if your baud rates are mismatched you should at least get a whole lot of rubbish characters showing up. If you get nothing get your oscilloscope then probe the TX pin of the shield , if you don't have an oscilloscope consider buying one - you need one - even a super cheapie of eBay is worth every dollar * 1000, without a scope everything is just a big old guess).

Otherwise if you have a logic analyser you can use that to check the TX line from GSM Module, or maybe even get by with a multimeter. Or if you have a FTDI cable or other TTL serial to USB cable you can connect the RX of that to the TX of the GSM Module and see if you can capture any serial data. You really need to have at least one if not all of these test equipment options to work out whats going on - otherwise your just jumping pins everywhere in random combinations hoping something will work.

Hey Ben,

I did what you said and it does work. The problem was with the pins. Thank you for that. However, now I have another issue. I am trying to connect both the shield (serial 3 on Due) and a puprletooth jamboree bluetooth module (Serial2 on Due). When both are connected to Due only the BT module works and the cellular shield stops responding. Both are connected to an external power source. Any idea as to why? Is the board unable to drive both together?

Thank you.